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