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