Browse Source

Cleanup server starting code for clients directly linked with libjackserver.so.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@3248 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/1.9.1
sletz 17 years ago
parent
commit
32a83a3df7
8 changed files with 51 additions and 65 deletions
  1. +4
    -0
      ChangeLog
  2. +4
    -3
      common/JackInternalClient.cpp
  3. +2
    -2
      common/JackNetAdapter.cpp
  4. +5
    -6
      common/JackServer.cpp
  5. +0
    -1
      common/JackServer.h
  6. +11
    -21
      common/JackServerAPI.cpp
  7. +19
    -26
      common/JackServerGlobals.cpp
  8. +6
    -6
      common/JackServerGlobals.h

+ 4
- 0
ChangeLog View File

@@ -23,6 +23,10 @@ Michael Voigt
Jackdmp changes log
---------------------------

2009-01-14 Stephane Letz <letz@grame.fr>

* Cleanup server starting code for clients directly linked with libjackserver.so.

2009-01-07 Stephane Letz <letz@grame.fr>

* Use up to BUFFER_SIZE_MAX frames in midi ports, fix for ticket #117.


+ 4
- 3
common/JackInternalClient.cpp View File

@@ -19,6 +19,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "JackSystemDeps.h"
#include "JackServerGlobals.h"
#include "JackGraphManager.h"
#include "JackConstants.h"
#include "JackInternalClient.h"
@@ -87,17 +88,17 @@ JackEngineControl* JackInternalClient::fEngineControl = NULL;
// Used for external C API (JackAPI.cpp)
JackGraphManager* GetGraphManager()
{
return JackServer::fInstance->GetGraphManager();
return JackServerGlobals::fInstance->GetGraphManager();
}

JackEngineControl* GetEngineControl()
{
return JackServer::fInstance->GetEngineControl();
return JackServerGlobals::fInstance->GetEngineControl();
}

JackSynchro* GetSynchroTable()
{
return JackServer::fInstance->GetSynchroTable();
return JackServerGlobals::fInstance->GetSynchroTable();
}

JackInternalClient::JackInternalClient(JackServer* server, JackSynchro* table): JackClient(table)


+ 2
- 2
common/JackNetAdapter.cpp View File

@@ -18,7 +18,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#include "JackNetAdapter.h"
#include "JackException.h"
#include "JackServer.h"
#include "JackServerGlobals.h"
#include "JackEngineControl.h"

namespace Jack
@@ -216,7 +216,7 @@ namespace Jack
SetAdaptedBufferSize ( fParams.fPeriodSize );
SetAdaptedSampleRate ( fParams.fSampleRate );
if (fThread.AcquireRealTime ( JackServer::fInstance->GetEngineControl()->fClientPriority ) < 0) {
if (fThread.AcquireRealTime ( JackServerGlobals::fInstance->GetEngineControl()->fClientPriority ) < 0) {
jack_error("AcquireRealTime error");
} else {
set_threaded_log_function();


+ 5
- 6
common/JackServer.cpp View File

@@ -19,7 +19,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "JackSystemDeps.h"
#include "JackServer.h"
#include "JackServerGlobals.h"
#include "JackTime.h"
#include "JackFreewheelDriver.h"
#include "JackLoopbackDriver.h"
@@ -38,8 +38,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{

JackServer* JackServer::fInstance = NULL;

JackServer::JackServer(bool sync, bool temporary, long timeout, bool rt, long priority, long loopback, bool verbose, const char* server_name)
{
if (rt) {
@@ -56,7 +54,8 @@ JackServer::JackServer(bool sync, bool temporary, long timeout, bool rt, long pr
fAudioDriver = NULL;
fFreewheel = false;
fLoopback = loopback;
fInstance = this; // Unique instance
JackServerGlobals::fInstance = this; // Unique instance
JackServerGlobals::fUserCount = 1; // One user
jack_verbose = verbose;
}

@@ -159,14 +158,14 @@ int JackServer::Close()

int JackServer::InternalClientLoad(const char* client_name, const char* so_name, const char* objet_data, int options, int* int_ref, int* status)
{
JackLoadableInternalClient* client = new JackLoadableInternalClient1(fInstance, GetSynchroTable(), so_name, objet_data);
JackLoadableInternalClient* client = new JackLoadableInternalClient1(JackServerGlobals::fInstance, GetSynchroTable(), so_name, objet_data);
assert(client);
return InternalClientLoadAux(client, so_name, client_name, options, int_ref, status);
}

int JackServer::InternalClientLoad(const char* client_name, const char* so_name, const JSList * parameters, int options, int* int_ref, int* status)
{
JackLoadableInternalClient* client = new JackLoadableInternalClient2(fInstance, GetSynchroTable(), so_name, parameters);
JackLoadableInternalClient* client = new JackLoadableInternalClient2(JackServerGlobals::fInstance, GetSynchroTable(), so_name, parameters);
assert(client);
return InternalClientLoadAux(client, so_name, client_name, options, int_ref, status);
}


+ 0
- 1
common/JackServer.h View File

@@ -93,7 +93,6 @@ class SERVER_EXPORT JackServer
JackSynchro* GetSynchroTable();
JackGraphManager* GetGraphManager();

static JackServer* fInstance; // Unique instance
};

} // end of namespace


+ 11
- 21
common/JackServerAPI.cpp View File

@@ -48,9 +48,6 @@ extern "C"

using namespace Jack;

// beware!!! things can go nasty if one client is started with JackNoStartServer and another without it
static bool g_nostart;

EXPORT jack_client_t* jack_client_open_aux(const char* ext_client_name, jack_options_t options, jack_status_t* status, va_list ap)
{
jack_varargs_t va; /* variable arguments */
@@ -84,27 +81,22 @@ EXPORT jack_client_t* jack_client_open_aux(const char* ext_client_name, jack_opt
jack_varargs_init(&va);
}

g_nostart = (options & JackNoStartServer) != 0;
if (!g_nostart) {
if (!JackServerGlobals::Init()) { // jack server initialisation
int my_status1 = (JackFailure | JackServerError);
*status = (jack_status_t)my_status1;
return NULL;
}
if (!JackServerGlobals::Init()) { // jack server initialisation
int my_status1 = (JackFailure | JackServerError);
*status = (jack_status_t)my_status1;
return NULL;
}
if (JACK_DEBUG) {
client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
client = new JackDebugClient(new JackInternalClient(JackServerGlobals::fInstance, GetSynchroTable())); // Debug mode
} else {
client = new JackInternalClient(JackServer::fInstance, GetSynchroTable());
client = new JackInternalClient(JackServerGlobals::fInstance, GetSynchroTable());
}

int res = client->Open(va.server_name, client_name, options, status);
if (res < 0) {
delete client;
if (!g_nostart) {
JackServerGlobals::Destroy(); // jack server destruction
}
JackServerGlobals::Destroy(); // jack server destruction
int my_status1 = (JackFailure | JackServerError);
*status = (jack_status_t)my_status1;
return NULL;
@@ -137,9 +129,7 @@ EXPORT int jack_client_close(jack_client_t* ext_client)
} else {
res = client->Close();
delete client;
if (!g_nostart) {
JackServerGlobals::Destroy(); // jack server destruction
}
JackServerGlobals::Destroy(); // jack server destruction
jack_log("jack_client_close res = %d", res);
}
JackGlobals::fOpenMutex->Unlock();
@@ -148,8 +138,8 @@ EXPORT int jack_client_close(jack_client_t* ext_client)

EXPORT int jack_get_client_pid(const char *name)
{
return (JackServer::fInstance != NULL)
? JackServer::fInstance->GetEngine()->GetClientPID(name)
return (JackServerGlobals::fInstance != NULL)
? JackServerGlobals::fInstance->GetEngine()->GetClientPID(name)
: 0;
}


+ 19
- 26
common/JackServerGlobals.cpp View File

@@ -28,8 +28,8 @@ static char* server_name = NULL;
namespace Jack
{

unsigned int JackServerGlobals::fClientCount = 0;
JackServer* JackServerGlobals::fServer = NULL;
JackServer* JackServerGlobals::fInstance;
unsigned int JackServerGlobals::fUserCount;

int JackServerGlobals::Start(const char* server_name,
jack_driver_desc_t* driver_desc,
@@ -43,34 +43,27 @@ int JackServerGlobals::Start(const char* server_name,
int verbose)
{
jack_log("Jackdmp: sync = %ld timeout = %ld rt = %ld priority = %ld verbose = %ld ", sync, time_out_ms, rt, priority, verbose);
fServer = new JackServer(sync, temporary, time_out_ms, rt, priority, loopback, verbose, server_name);
int res = fServer->Open(driver_desc, driver_params);
return (res < 0) ? res : fServer->Start();
new JackServer(sync, temporary, time_out_ms, rt, priority, loopback, verbose, server_name); // Will setup fInstance and fUserCount globals
int res = fInstance->Open(driver_desc, driver_params);
return (res < 0) ? res : fInstance->Start();
}

int JackServerGlobals::Stop()
void JackServerGlobals::Stop()
{
fServer->Stop();
fServer->Close();
jack_log("Jackdmp: server close");
delete fServer;
jack_log("Jackdmp: delete server");
return 0;
fInstance->Stop();
fInstance->Close();
}

int JackServerGlobals::Delete()
void JackServerGlobals::Delete()
{
delete fServer;
jack_log("Jackdmp: delete server");
return 0;
delete fInstance;
fInstance = NULL;
}

bool JackServerGlobals::Init()
{
// Server already started
if (JackServer::fInstance != NULL)
return true;

int realtime = 0;
int client_timeout = 0; /* msecs; if zero, use period size. */
int realtime_priority = 10;
@@ -86,7 +79,7 @@ bool JackServerGlobals::Init()
int seen_driver = 0;
char *driver_name = NULL;
char **driver_args = NULL;
JSList* driver_params;
JSList* driver_params = NULL;
int driver_nargs = 1;
JSList* drivers = NULL;
int show_version = 0;
@@ -99,17 +92,16 @@ bool JackServerGlobals::Init()
char buffer[255];
int argc = 0;
char* argv[32];
// Otherwise first client starts the server
if (fClientCount++ == 0) {
// First user starts the server
if (fUserCount++ == 0) {

jack_log("JackServerGlobals Init");

jack_driver_desc_t* driver_desc;
const char *options = "-ad:P:uvshVRL:STFl:t:mn:p:";
static struct option long_options[] = {
{ "driver", 1, 0, 'd'
},
{ "driver", 1, 0, 'd' },
{ "verbose", 0, 0, 'v' },
{ "help", 0, 0, 'h' },
{ "port-max", 1, 0, 'p' },
@@ -307,15 +299,16 @@ bool JackServerGlobals::Init()
error:
if (driver_params)
jack_free_driver_params(driver_params);
fClientCount--;
fUserCount--;
return false;
}

void JackServerGlobals::Destroy()
{
if (--fClientCount == 0) {
if (--fUserCount == 0) {
jack_log("JackServerGlobals Destroy");
Stop();
Delete();
jack_cleanup_shm();
JackTools::CleanupFiles(server_name);
jack_unregister_server(server_name);


+ 6
- 6
common/JackServerGlobals.h View File

@@ -34,11 +34,11 @@ class JackClient;
\brief Global server static structure: singleton kind of pattern.
*/

struct JackServerGlobals
struct SERVER_EXPORT JackServerGlobals
{
static unsigned int fClientCount;
static JackServer* fServer;
static JackServer* fInstance;
static unsigned int fUserCount;
JackServerGlobals();
~JackServerGlobals();

@@ -54,8 +54,8 @@ struct JackServerGlobals
int priority,
int loopback,
int verbose);
static int Stop();
static int Delete();
static void Stop();
static void Delete();
};

} // end of namespace


Loading…
Cancel
Save