Callback for the connect function.
| 534 | |
| 535 | // Callback for the connect function. |
| 536 | NymphMessage* connectClient(int session, NymphMessage* msg, void* data) { |
| 537 | NYMPH_LOG_INFORMATION("Received message for session: " + Poco::NumberFormatter::format(session) |
| 538 | + ", msg ID: " + Poco::NumberFormatter::format(msg->getMessageId())); |
| 539 | |
| 540 | std::string clientStr = msg->parameters()[0]->getString(); |
| 541 | NYMPH_LOG_INFORMATION("Client string: " + clientStr); |
| 542 | |
| 543 | // TODO: check whether we're not operating in slave or master mode already. |
| 544 | NYMPH_LOG_INFORMATION("Switching to stand-alone server mode."); |
| 545 | serverMode = NCS_MODE_STANDALONE; |
| 546 | |
| 547 | // Register this client with its ID. Return error if the client ID already exists. |
| 548 | NymphMessage* returnMsg = msg->getReplyMessage(); |
| 549 | std::map<int, CastClient>::iterator it; |
| 550 | it = clients.find(session); |
| 551 | NymphType* retVal = 0; |
| 552 | if (it != clients.end()) { |
| 553 | // Client ID already exists, abort. |
| 554 | retVal = new NymphType(false); |
| 555 | } |
| 556 | else { |
| 557 | CastClient c; |
| 558 | c.name = clientStr; |
| 559 | c.handle = session; |
| 560 | c.sessionActive = false; |
| 561 | c.filesize = 0; |
| 562 | clients.insert(std::pair<int, CastClient>(session, c)); |
| 563 | retVal = new NymphType(true); |
| 564 | } |
| 565 | |
| 566 | // Send the client the current playback status. |
| 567 | std::vector<NymphType*> values; |
| 568 | std::map<std::string, NymphPair>* status = getPlaybackStatus(); |
| 569 | values.push_back(new NymphType(status, true)); |
| 570 | std::string result; |
| 571 | if (!NymphRemoteClient::callCallback(session, "MediaStatusCallback", values, result)) { |
| 572 | NYMPH_LOG_ERROR("Calling media status callback failed: " + result); |
| 573 | } |
| 574 | |
| 575 | returnMsg->setResultValue(retVal); |
| 576 | msg->discard(); |
| 577 | |
| 578 | return returnMsg; |
| 579 | } |
| 580 | |
| 581 | |
| 582 | // --- CONNECT MASTER --- |
nothing calls this directly
no test coverage detected