mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-10 07:36:41 +02:00
removed request message
This commit is contained in:
parent
c014b3a097
commit
bd7f68bb6a
7 changed files with 16 additions and 98 deletions
Binary file not shown.
Binary file not shown.
|
@ -28,7 +28,6 @@
|
|||
#include "common/log.h"
|
||||
#include "common/snapException.h"
|
||||
#include "message/time.h"
|
||||
#include "message/request.h"
|
||||
#include "message/hello.h"
|
||||
#include "controller.h"
|
||||
|
||||
|
@ -139,7 +138,7 @@ bool Controller::sendTimeSyncMessage(long after)
|
|||
return false;
|
||||
|
||||
lastTimeSync = now;
|
||||
msg::Request timeReq(kTime);
|
||||
msg::Time timeReq;
|
||||
clientConnection_->send(&timeReq);
|
||||
return true;
|
||||
}
|
||||
|
@ -176,7 +175,7 @@ void Controller::worker()
|
|||
msg::Hello hello(clientConnection_->getMacAddress());
|
||||
clientConnection_->send(&hello);
|
||||
|
||||
msg::Request timeReq(kTime);
|
||||
msg::Time timeReq;
|
||||
for (size_t n=0; n<50 && active_; ++n)
|
||||
{
|
||||
shared_ptr<msg::Time> reply = clientConnection_->sendReq<msg::Time>(&timeReq, chronos::msec(2000));
|
||||
|
|
|
@ -55,8 +55,7 @@ enum message_type
|
|||
kWireChunk = 2,
|
||||
kServerSettings = 3,
|
||||
kTime = 4,
|
||||
kRequest = 5,
|
||||
kHello = 6
|
||||
kHello = 5
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
/***
|
||||
This file is part of snapcast
|
||||
Copyright (C) 2014-2016 Johannes Pohl
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#ifndef REQUEST_MSG_H
|
||||
#define REQUEST_MSG_H
|
||||
|
||||
#include "message.h"
|
||||
#include <string>
|
||||
|
||||
namespace msg
|
||||
{
|
||||
|
||||
/**
|
||||
* Request is sent from client to server. The answer is identified by a request id
|
||||
*/
|
||||
class Request : public BaseMessage
|
||||
{
|
||||
public:
|
||||
Request() : BaseMessage(message_type::kRequest), request(kBase)
|
||||
{
|
||||
}
|
||||
|
||||
Request(message_type _request) : BaseMessage(message_type::kRequest), request(_request)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~Request()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void read(std::istream& stream)
|
||||
{
|
||||
uint16_t i;
|
||||
readVal(stream, i);
|
||||
request = (message_type)i;
|
||||
}
|
||||
|
||||
virtual uint32_t getSize() const
|
||||
{
|
||||
return sizeof(int16_t);
|
||||
}
|
||||
|
||||
message_type request;
|
||||
|
||||
protected:
|
||||
virtual void doserialize(std::ostream& stream) const
|
||||
{
|
||||
uint16_t i = request;
|
||||
writeVal(stream, i);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
#include "controlServer.h"
|
||||
#include "message/time.h"
|
||||
#include "message/request.h"
|
||||
#include "common/log.h"
|
||||
#include "common/utils.h"
|
||||
#include "common/snapException.h"
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "json/jsonrpc.h"
|
||||
#include "streamServer.h"
|
||||
#include "message/time.h"
|
||||
#include "message/request.h"
|
||||
#include "message/hello.h"
|
||||
#include "common/log.h"
|
||||
#include "config.h"
|
||||
|
@ -241,26 +240,21 @@ void StreamServer::onMessageReceived(ControlSession* controlSession, const std::
|
|||
void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseMessage& baseMessage, char* buffer)
|
||||
{
|
||||
logD << "getNextMessage: " << baseMessage.type << ", size: " << baseMessage.size << ", id: " << baseMessage.id << ", refers: " << baseMessage.refersTo << ", sent: " << baseMessage.sent.sec << "," << baseMessage.sent.usec << ", recv: " << baseMessage.received.sec << "," << baseMessage.received.usec << "\n";
|
||||
if (baseMessage.type == message_type::kRequest)
|
||||
if (baseMessage.type == message_type::kTime)
|
||||
{
|
||||
msg::Request requestMsg;
|
||||
requestMsg.deserialize(baseMessage, buffer);
|
||||
logD << "request: " << requestMsg.request << "\n";
|
||||
if (requestMsg.request == kTime)
|
||||
{
|
||||
msg::Time timeMsg;
|
||||
timeMsg.refersTo = requestMsg.id;
|
||||
timeMsg.latency = requestMsg.received - requestMsg.sent;
|
||||
// logO << "Latency sec: " << timeMsg.latency.sec << ", usec: " << timeMsg.latency.usec << ", refers to: " << timeMsg.refersTo << "\n";
|
||||
connection->send(&timeMsg);
|
||||
msg::Time timeMsg;
|
||||
timeMsg.deserialize(baseMessage, buffer);
|
||||
timeMsg.refersTo = timeMsg.id;
|
||||
timeMsg.latency = timeMsg.received - timeMsg.sent;
|
||||
// logO << "Latency sec: " << timeMsg.latency.sec << ", usec: " << timeMsg.latency.usec << ", refers to: " << timeMsg.refersTo << "\n";
|
||||
connection->send(&timeMsg);
|
||||
|
||||
// refresh connection state
|
||||
ClientInfoPtr client = Config::instance().getClientInfo(connection->macAddress);
|
||||
if (client != nullptr)
|
||||
{
|
||||
gettimeofday(&client->lastSeen, NULL);
|
||||
client->connected = true;
|
||||
}
|
||||
// refresh connection state
|
||||
ClientInfoPtr client = Config::instance().getClientInfo(connection->macAddress);
|
||||
if (client != nullptr)
|
||||
{
|
||||
gettimeofday(&client->lastSeen, NULL);
|
||||
client->connected = true;
|
||||
}
|
||||
}
|
||||
else if (baseMessage.type == message_type::kHello)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue