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)
00065 {
00066 int shared_engine, shared_client, shared_graph, result;
00067 JackLog("JackLibClient::Open %s\n", name);
00068
00069
00070 if (fChannel->Open(name, this) < 0) {
00071 jack_error("Cannot connect to the server");
00072 goto error;
00073 }
00074
00075
00076 if (fChannel->Start() < 0) {
00077 jack_error("Cannot start channel");
00078 goto error;
00079 }
00080
00081
00082 fChannel->ClientNew(name, &shared_engine, &shared_client, &shared_graph, &result);
00083 if (result < 0) {
00084 jack_error("Cannot open %s client", name);
00085 goto error;
00086 }
00087
00088 try {
00089
00090 JackLibGlobals::fGlobals->fEngineControl = shared_engine;
00091 JackLibGlobals::fGlobals->fGraphManager = shared_graph;
00092 fClientControl = shared_client;
00093 jack_verbose = GetEngineControl()->fVerbose;
00094 } catch (int n) {
00095 jack_error("Map shared memory segments exception %d", n);
00096 goto error;
00097 }
00098
00099 SetupDriverSync(false);
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 if (!fSynchroTable[fClientControl->fRefNum]->Connect(name)) {
00112 jack_error("Cannot ConnectSemaphore %s client", name);
00113 goto error;
00114 }
00115
00116 JackLog("JackLibClient::Open name = %s refnum = %ld\n", name, fClientControl->fRefNum);
00117
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 JackNotifyChannelInterface::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 JackNotifyChannelInterface::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