00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "JackLibClient.h"
00021 #include "JackTime.h"
00022 #include "JackLibGlobals.h"
00023 #include "JackGlobals.h"
00024 #include "JackPlatformPlug.h"
00025 #include "JackTools.h"
00026
00027 namespace Jack
00028 {
00029
00030
00031 JackGraphManager* GetGraphManager()
00032 {
00033 if (JackLibGlobals::fGlobals) {
00034 return JackLibGlobals::fGlobals->fGraphManager;
00035 } else {
00036 return NULL;
00037 }
00038 }
00039
00040 JackEngineControl* GetEngineControl()
00041 {
00042 if (JackLibGlobals::fGlobals) {
00043 return JackLibGlobals::fGlobals->fEngineControl;
00044 } else {
00045 return NULL;
00046 }
00047 }
00048
00049 JackSynchro* GetSynchroTable()
00050 {
00051 return (JackLibGlobals::fGlobals ? JackLibGlobals::fGlobals->fSynchroTable : 0);
00052 }
00053
00054
00055
00056
00057
00058 JackLibClient::JackLibClient(JackSynchro* table): JackClient(table)
00059 {
00060 jack_log("JackLibClient::JackLibClient table = %x", table);
00061 fChannel = new JackClientChannel();
00062 }
00063
00064 JackLibClient::~JackLibClient()
00065 {
00066 jack_log("JackLibClient::~JackLibClient");
00067 delete fChannel;
00068 }
00069
00070 int JackLibClient::Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status)
00071 {
00072 int shared_engine, shared_client, shared_graph, result;
00073 jack_log("JackLibClient::Open name = %s", name);
00074
00075 snprintf(fServerName, sizeof(fServerName), server_name);
00076
00077
00078 char name_res[JACK_CLIENT_NAME_SIZE + 1];
00079 if (fChannel->Open(server_name, name, name_res, this, options, status) < 0) {
00080 jack_error("Cannot connect to the server");
00081 goto error;
00082 }
00083
00084
00085 if (fChannel->Start() < 0) {
00086 jack_error("Cannot start channel");
00087 goto error;
00088 }
00089
00090
00091 fChannel->ClientOpen(name_res, JackTools::GetPID(), &shared_engine, &shared_client, &shared_graph, &result);
00092 if (result < 0) {
00093 jack_error("Cannot open %s client", name_res);
00094 goto error;
00095 }
00096
00097 try {
00098
00099 JackLibGlobals::fGlobals->fEngineControl.SetShmIndex(shared_engine, fServerName);
00100 JackLibGlobals::fGlobals->fGraphManager.SetShmIndex(shared_graph, fServerName);
00101 fClientControl.SetShmIndex(shared_client, fServerName);
00102 jack_verbose = GetEngineControl()->fVerbose;
00103 } catch (int n) {
00104 jack_error("Map shared memory segments exception %d", n);
00105 goto error;
00106 }
00107
00108 SetupDriverSync(false);
00109
00110
00111 if (!fSynchroTable[GetClientControl()->fRefNum].Connect(name_res, fServerName)) {
00112 jack_error("Cannot ConnectSemaphore %s client", name_res);
00113 goto error;
00114 }
00115
00116 JackGlobals::fClientTable[GetClientControl()->fRefNum] = this;
00117 JackGlobals::fServerRunning = true;
00118 jack_log("JackLibClient::Open name = %s refnum = %ld", name_res, GetClientControl()->fRefNum);
00119 return 0;
00120
00121 error:
00122 fChannel->Stop();
00123 fChannel->Close();
00124 return -1;
00125 }
00126
00127
00128
00129
00130 int JackLibClient::ClientNotifyImp(int refnum, const char* name, int notify, int sync, int value1, int value2)
00131 {
00132 int res = 0;
00133
00134
00135 switch (notify) {
00136
00137 case kAddClient:
00138 jack_log("JackClient::AddClient name = %s, ref = %ld ", name, refnum);
00139
00140 res = fSynchroTable[refnum].Connect(name, fServerName) ? 0 : -1;
00141 break;
00142
00143 case kRemoveClient:
00144 jack_log("JackClient::RemoveClient name = %s, ref = %ld ", name, refnum);
00145 if (strcmp(GetClientControl()->fName, name) != 0)
00146 res = fSynchroTable[refnum].Disconnect() ? 0 : -1;
00147 break;
00148 }
00149
00150 return res;
00151 }
00152
00153 JackGraphManager* JackLibClient::GetGraphManager() const
00154 {
00155 assert(JackLibGlobals::fGlobals->fGraphManager);
00156 return JackLibGlobals::fGlobals->fGraphManager;
00157 }
00158
00159 JackEngineControl* JackLibClient::GetEngineControl() const
00160 {
00161 assert(JackLibGlobals::fGlobals->fEngineControl);
00162 return JackLibGlobals::fGlobals->fEngineControl;
00163 }
00164
00165 JackClientControl* JackLibClient::GetClientControl() const
00166 {
00167 return fClientControl;
00168 }
00169
00170 }
00171
00172
00173