Client info fully functional
This commit is contained in:
parent
10607c37f0
commit
2c9e458906
|
|
@ -658,7 +658,7 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
|
|||
for (client_it = m_client_map.begin(); client_it != m_client_map.end(); ++client_it)
|
||||
{
|
||||
ReflectorClient* client = client_it->second;
|
||||
Json::Value node(Json::objectValue);
|
||||
Json::Value node(client->clientInfo());
|
||||
node["addr"] = client->remoteHost().toString();
|
||||
node["protoVer"]["majorVer"] = client->protoVer().majorVer();
|
||||
node["protoVer"]["minorVer"] = client->protoVer().minorVer();
|
||||
|
|
@ -675,19 +675,52 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
|
|||
TGHandler::instance()->talkerForTG(client->currentTG()) == client;
|
||||
node["isTalker"] = is_talker;
|
||||
|
||||
std::vector<char> rx_ids = client->rxIdList();
|
||||
for (std::vector<char>::const_iterator it=rx_ids.begin();
|
||||
it!=rx_ids.end(); ++it)
|
||||
if (node.isMember("qth") && node["qth"].isArray())
|
||||
{
|
||||
Json::Value rx(Json::objectValue);
|
||||
std::string id_str(&(*it), &(*it)+1);
|
||||
rx["id"] = id_str;
|
||||
rx["siglev"] = client->rxSiglev(*it);
|
||||
rx["enabled"] = client->rxEnabled(*it);
|
||||
rx["sql_open"] = client->rxSqlOpen(*it);
|
||||
rx["active"] = client->rxActive(*it);
|
||||
node["rx"][id_str] = rx;
|
||||
//std::cout << "### Found qth" << std::endl;
|
||||
Json::Value& qths(node["qth"]);
|
||||
for (Json::Value::ArrayIndex i=0; i<qths.size(); ++i)
|
||||
{
|
||||
Json::Value& qth(qths[i]);
|
||||
if (qth.isMember("rx") && qth["rx"].isObject())
|
||||
{
|
||||
//std::cout << "### Found rx" << std::endl;
|
||||
Json::Value::Members rxs(qth["rx"].getMemberNames());
|
||||
for (Json::Value::Members::const_iterator it=rxs.begin(); it!=rxs.end(); ++it)
|
||||
{
|
||||
//std::cout << "### member=" << *it << std::endl;
|
||||
const std::string& rx_id_str(*it);
|
||||
if (rx_id_str.size() == 1)
|
||||
{
|
||||
char rx_id(rx_id_str[0]);
|
||||
Json::Value& rx(qth["rx"][rx_id_str]);
|
||||
//rx_id_map[rx_id_str[0]] = ℞
|
||||
if (client->rxExist(rx_id))
|
||||
{
|
||||
rx["siglev"] = client->rxSiglev(rx_id);
|
||||
rx["enabled"] = client->rxEnabled(rx_id);
|
||||
rx["sql_open"] = client->rxSqlOpen(rx_id);
|
||||
rx["active"] = client->rxActive(rx_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//std::vector<char> rx_ids = client->rxIdList();
|
||||
//for (std::vector<char>::const_iterator it=rx_ids.begin();
|
||||
// it!=rx_ids.end(); ++it)
|
||||
//{
|
||||
// Json::Value rx(Json::objectValue);
|
||||
// std::string id_str(&(*it), &(*it)+1);
|
||||
// rx["id"] = id_str;
|
||||
// rx["siglev"] = client->rxSiglev(*it);
|
||||
// rx["enabled"] = client->rxEnabled(*it);
|
||||
// rx["sql_open"] = client->rxSqlOpen(*it);
|
||||
// rx["active"] = client->rxActive(*it);
|
||||
// node["rxStatus"][id_str] = rx;
|
||||
//}
|
||||
status["nodes"][client->callsign()] = node;
|
||||
}
|
||||
std::ostringstream os;
|
||||
|
|
|
|||
|
|
@ -312,8 +312,8 @@ void ReflectorClient::onFrameReceived(FramedTcpConnection *con,
|
|||
case MsgTgMonitor::TYPE:
|
||||
handleTgMonitor(ss);
|
||||
break;
|
||||
case MsgClientInfoJson::TYPE:
|
||||
handleClientInfoJson(ss);
|
||||
case MsgClientInfo::TYPE:
|
||||
handleClientInfo(ss);
|
||||
break;
|
||||
#if 0
|
||||
case MsgClientInfo::TYPE:
|
||||
|
|
@ -498,18 +498,29 @@ void ReflectorClient::handleTgMonitor(std::istream& is)
|
|||
} /* ReflectorClient::handleTgMonitor */
|
||||
|
||||
|
||||
void ReflectorClient::handleClientInfoJson(std::istream& is)
|
||||
void ReflectorClient::handleClientInfo(std::istream& is)
|
||||
{
|
||||
MsgClientInfoJson msg;
|
||||
MsgClientInfo msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
cout << "Client " << m_con->remoteHost() << ":" << m_con->remotePort()
|
||||
<< " ERROR: Could not unpack MsgClientInfoJson" << endl;
|
||||
sendError("Illegal MsgClientInfoJson protocol message received");
|
||||
<< " ERROR: Could not unpack MsgClientInfo" << endl;
|
||||
sendError("Illegal MsgClientInfo protocol message received");
|
||||
return;
|
||||
}
|
||||
std::cout << "### handleClientInfoJson: " << msg.json() << std::endl;
|
||||
} /* ReflectorClient::handleClientInfoJson */
|
||||
//std::cout << "### handleClientInfo: " << msg.json() << std::endl;
|
||||
try
|
||||
{
|
||||
std::istringstream is(msg.json());
|
||||
is >> m_client_info;
|
||||
}
|
||||
catch (const Json::Exception& e)
|
||||
{
|
||||
std::cerr << "*** WARNING[" << m_callsign
|
||||
<< "]: Failed to parse MsgClientInfo JSON object: "
|
||||
<< e.what() << std::endl;
|
||||
}
|
||||
} /* ReflectorClient::handleClientInfo */
|
||||
|
||||
|
||||
void ReflectorClient::handleRequestQsy(std::istream& is)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
****************************************************************************/
|
||||
|
||||
#include <string>
|
||||
#include <json/json.h>
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -378,6 +379,10 @@ class ReflectorClient
|
|||
}
|
||||
return ids;
|
||||
}
|
||||
bool rxExist(char rx_id) const
|
||||
{
|
||||
return m_rx_map.find(rx_id) != m_rx_map.end();
|
||||
}
|
||||
const std::string& rxName(char id) { return m_rx_map[id].name; }
|
||||
void setRxSiglev(char id, uint8_t siglev) { m_rx_map[id].siglev = siglev; }
|
||||
uint8_t rxSiglev(char id) { return m_rx_map[id].siglev; }
|
||||
|
|
@ -389,6 +394,7 @@ class ReflectorClient
|
|||
bool rxActive(char id) { return m_rx_map[id].active; }
|
||||
//RxMap& rxMap(void) { return m_rx_map; }
|
||||
//const RxMap& rxMap(void) const { return m_rx_map; }
|
||||
const Json::Value& clientInfo(void) const { return m_client_info; }
|
||||
|
||||
private:
|
||||
static const uint16_t MIN_MAJOR_VER = 0;
|
||||
|
|
@ -423,6 +429,7 @@ class ReflectorClient
|
|||
uint32_t m_current_tg;
|
||||
std::set<uint32_t> m_monitored_tgs;
|
||||
RxMap m_rx_map;
|
||||
Json::Value m_client_info;
|
||||
|
||||
ReflectorClient(const ReflectorClient&);
|
||||
ReflectorClient& operator=(const ReflectorClient&);
|
||||
|
|
@ -432,8 +439,7 @@ class ReflectorClient
|
|||
void handleMsgAuthResponse(std::istream& is);
|
||||
void handleSelectTG(std::istream& is);
|
||||
void handleTgMonitor(std::istream& is);
|
||||
void handleClientInfoJson(std::istream& is);
|
||||
//void handleClientInfo(std::istream& is);
|
||||
void handleClientInfo(std::istream& is);
|
||||
void handleRequestQsy(std::istream& is);
|
||||
void handleStateEvent(std::istream& is);
|
||||
void handleMsgError(std::istream& is);
|
||||
|
|
|
|||
|
|
@ -933,10 +933,10 @@ This message is sent by a client to inform the reflector server about various
|
|||
facts about the client. JSON is used so that information can be added without
|
||||
redefining the message type.
|
||||
*/
|
||||
class MsgClientInfoJson : public ReflectorMsgBase<111>
|
||||
class MsgClientInfo : public ReflectorMsgBase<111>
|
||||
{
|
||||
public:
|
||||
MsgClientInfoJson(const std::string& json="")
|
||||
MsgClientInfo(const std::string& json="")
|
||||
: m_json(json) {}
|
||||
|
||||
const std::string& json(void) const { return m_json; }
|
||||
|
|
@ -945,7 +945,7 @@ class MsgClientInfoJson : public ReflectorMsgBase<111>
|
|||
|
||||
private:
|
||||
std::string m_json;
|
||||
}; /* MsgClientInfoJson */
|
||||
}; /* MsgClientInfo */
|
||||
|
||||
|
||||
/***************************** UDP Messages *****************************/
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <json/json.h>
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -47,7 +47,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
#include <AsyncTcpClient.h>
|
||||
#include <AsyncUdpSocket.h>
|
||||
#include <AsyncAudioPassthrough.h>
|
||||
//#include <version/SVXLINK.h>
|
||||
#include <version/SVXLINK.h>
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -301,6 +301,42 @@ bool ReflectorLogic::initialize(void)
|
|||
return false;
|
||||
}
|
||||
|
||||
std::string client_info_file;
|
||||
if (cfg().getValue(name(), "CLIENT_INFO_FILE", client_info_file))
|
||||
{
|
||||
std::ifstream client_info_is(client_info_file, std::ios::in);
|
||||
if (client_info_is.good())
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!(client_info_is >> m_client_info))
|
||||
{
|
||||
std::cerr << "*** ERROR: Failure while reading client information file "
|
||||
"\"" << client_info_file << "\""
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const Json::Exception& e)
|
||||
{
|
||||
std::cerr << "*** ERROR: Failure while reading client information "
|
||||
"file \"" << client_info_file << "\": "
|
||||
<< e.what()
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "*** ERROR: Could not open client information file "
|
||||
"\"" << client_info_file << "\""
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_client_info["sw"] = "SvxLink";
|
||||
m_client_info["swVer"] = SVXLINK_VERSION;
|
||||
|
||||
if (!LogicBase::initialize())
|
||||
{
|
||||
return false;
|
||||
|
|
@ -715,17 +751,13 @@ void ReflectorLogic::handleMsgServerInfo(std::istream& is)
|
|||
|
||||
m_con_state = STATE_CONNECTED;
|
||||
|
||||
Json::Value client_info;
|
||||
client_info["rx"] = Json::Value(Json::objectValue);
|
||||
std::ostringstream client_info_os;
|
||||
//client_info_os << client_info;
|
||||
|
||||
Json::StreamWriterBuilder builder;
|
||||
builder["commentStyle"] = "None";
|
||||
builder["indentation"] = ""; //The JSON document is written on a single line
|
||||
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
|
||||
writer->write(client_info, &client_info_os);
|
||||
MsgClientInfoJson client_info_msg(client_info_os.str());
|
||||
writer->write(m_client_info, &client_info_os);
|
||||
MsgClientInfo client_info_msg(client_info_os.str());
|
||||
sendMsg(client_info_msg);
|
||||
|
||||
#if 0
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
|
||||
#include <sys/time.h>
|
||||
#include <string>
|
||||
#include <json/json.h>
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -242,6 +243,7 @@ class ReflectorLogic : public LogicBase
|
|||
bool m_tg_local_activity;
|
||||
uint32_t m_last_qsy;
|
||||
MonitorTgsSet m_monitor_tgs;
|
||||
Json::Value m_client_info;
|
||||
|
||||
ReflectorLogic(const ReflectorLogic&);
|
||||
ReflectorLogic& operator=(const ReflectorLogic&);
|
||||
|
|
|
|||
Loading…
Reference in New Issue