128 |
FD_SET(hSocket, &fdSet); |
FD_SET(hSocket, &fdSet); |
129 |
int maxSessions = hSocket; |
int maxSessions = hSocket; |
130 |
|
|
131 |
|
timeval timeout; |
132 |
|
|
133 |
while (true) { |
while (true) { |
134 |
fd_set selectSet = fdSet; |
// check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers |
135 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL); |
{ |
136 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
137 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
138 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
139 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
140 |
|
if ((*itEngineChannel)->StatusChanged()) { |
141 |
|
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
142 |
|
} |
143 |
|
} |
144 |
|
} |
145 |
|
|
146 |
|
//Now let's deliver late notifies (if any) |
147 |
|
NotifyBufferMutex.Lock(); |
148 |
|
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
149 |
|
#ifdef MSG_NOSIGNAL |
150 |
|
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); |
151 |
|
#else |
152 |
|
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
153 |
|
#endif |
154 |
|
} |
155 |
|
bufferedNotifies.clear(); |
156 |
|
NotifyBufferMutex.Unlock(); |
157 |
|
|
158 |
|
fd_set selectSet = fdSet; |
159 |
|
timeout.tv_sec = 0; |
160 |
|
timeout.tv_usec = 100000; |
161 |
|
|
162 |
|
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
163 |
|
|
164 |
if (retval == 0) |
if (retval == 0) |
165 |
continue; //Nothing try again |
continue; //Nothing try again |
166 |
if (retval == -1) { |
if (retval == -1) { |
220 |
break; |
break; |
221 |
} |
} |
222 |
} |
} |
|
|
|
|
// check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers |
|
|
{ |
|
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
|
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
|
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
|
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
|
|
if ((*itEngineChannel)->StatusChanged()) { |
|
|
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
//Now let's deliver late notifies (if any) |
|
|
NotifyBufferMutex.Lock(); |
|
|
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
|
|
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); |
|
|
bufferedNotifies.erase(iterNotify); |
|
|
} |
|
|
NotifyBufferMutex.Unlock(); |
|
223 |
} |
} |
224 |
} |
} |
225 |
|
|
266 |
while (true) { |
while (true) { |
267 |
if (NotifyMutex.Trylock()) { |
if (NotifyMutex.Trylock()) { |
268 |
for(;iter != end; iter++) |
for(;iter != end; iter++) |
269 |
|
#ifdef MSG_NOSIGNAL |
270 |
send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL); |
send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL); |
271 |
|
#else |
272 |
|
send(*iter, notify.c_str(), notify.size(), 0); |
273 |
|
#endif |
274 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
275 |
break; |
break; |
276 |
} else { |
} else { |
379 |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
380 |
if (currentSocket != -1) { |
if (currentSocket != -1) { |
381 |
NotifyMutex.Lock(); |
NotifyMutex.Lock(); |
382 |
|
#ifdef MSG_NOSIGNAL |
383 |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); |
384 |
|
#else |
385 |
|
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
386 |
|
#endif |
387 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
388 |
} |
} |
389 |
} |
} |
564 |
*/ |
*/ |
565 |
String LSCPServer::AddChannel() { |
String LSCPServer::AddChannel() { |
566 |
dmsg(2,("LSCPServer: AddChannel()\n")); |
dmsg(2,("LSCPServer: AddChannel()\n")); |
567 |
|
LockRTNotify(); |
568 |
SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); |
SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); |
569 |
|
UnlockRTNotify(); |
570 |
LSCPResultSet result(pSamplerChannel->Index()); |
LSCPResultSet result(pSamplerChannel->Index()); |
571 |
return result.Produce(); |
return result.Produce(); |
572 |
} |
} |
608 |
String LSCPServer::GetEngineInfo(String EngineName) { |
String LSCPServer::GetEngineInfo(String EngineName) { |
609 |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
610 |
LSCPResultSet result; |
LSCPResultSet result; |
611 |
|
LockRTNotify(); |
612 |
try { |
try { |
613 |
Engine* pEngine = EngineFactory::Create(EngineName); |
Engine* pEngine = EngineFactory::Create(EngineName); |
614 |
result.Add("DESCRIPTION", pEngine->Description()); |
result.Add("DESCRIPTION", pEngine->Description()); |
618 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
619 |
result.Error(e); |
result.Error(e); |
620 |
} |
} |
621 |
|
UnlockRTNotify(); |
622 |
return result.Produce(); |
return result.Produce(); |
623 |
} |
} |
624 |
|
|
1249 |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
1250 |
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
1251 |
LSCPResultSet result; |
LSCPResultSet result; |
1252 |
|
LockRTNotify(); |
1253 |
try { |
try { |
1254 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1255 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1261 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1262 |
result.Error(e); |
result.Error(e); |
1263 |
} |
} |
1264 |
|
UnlockRTNotify(); |
1265 |
return result.Produce(); |
return result.Produce(); |
1266 |
} |
} |
1267 |
|
|
1268 |
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
1269 |
dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel)); |
1270 |
LSCPResultSet result; |
LSCPResultSet result; |
1271 |
|
LockRTNotify(); |
1272 |
try { |
try { |
1273 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1274 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1300 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1301 |
result.Error(e); |
result.Error(e); |
1302 |
} |
} |
1303 |
|
UnlockRTNotify(); |
1304 |
return result.Produce(); |
return result.Produce(); |
1305 |
} |
} |
1306 |
|
|