server RPC info op

This commit is contained in:
Matej Sekoranja
2014-10-13 22:31:13 +02:00
parent b75e058620
commit b539eaa4bd
4 changed files with 80 additions and 3 deletions

View File

@@ -54,7 +54,7 @@ bool Version::isDevelopmentVersion() const {
const string Version::getVersionString() const {
stringstream ret;
ret<<getProductName()<<" v"<<getMajorVersion()<<"."<<getMinorVersion()<<'.'<<getMaintenanceVersion();
ret<<getProductName()<<" v"<<getMajorVersion()<<'.'<<getMinorVersion()<<'.'<<getMaintenanceVersion();
if (isDevelopmentVersion())
ret<<"-SNAPSHOT";

View File

@@ -4,6 +4,12 @@
* in file LICENSE that is included with this distribution.
*/
#ifdef __vxworks
#include <taskLib.h>
#endif
#include <sstream>
#include <pv/responseHandlers.h>
#include <pv/remote.h>
#include <pv/hexDump.h>
@@ -13,6 +19,7 @@
#include <pv/byteBuffer.h>
#include <osiSock.h>
#include <osiProcess.h>
#include <pv/logger.h>
#include <sstream>
@@ -454,6 +461,7 @@ private:
static Structure::const_shared_pointer helpStructure;
static Structure::const_shared_pointer channelListStructure;
static Structure::const_shared_pointer infoStructure;
static std::string helpString;
@@ -511,6 +519,44 @@ public:
PVStringArray::shared_pointer pvArray = result->getSubField<PVStringArray>("value");
pvArray->replace(listListener->channelNames);
return result;
}
else if (op == "info")
{
PVStructure::shared_pointer result =
getPVDataCreate()->createPVStructure(infoStructure);
// TODO cache hostname in InetAddressUtil
char buffer[256];
std::string hostName("localhost");
if (gethostname(buffer, sizeof(buffer)) == 0)
hostName = buffer;
std::stringstream ret;
ret << EPICS_PVA_MAJOR_VERSION << '.' <<
EPICS_PVA_MINOR_VERSION << '.' <<
EPICS_PVA_MAINTENANCE_VERSION;
if (EPICS_PVA_DEVELOPMENT_FLAG)
ret << "-SNAPSHOT";
result->getSubField<PVString>("version")->put(ret.str());
result->getSubField<PVString>("implLang")->put("cpp");
result->getSubField<PVString>("host")->put(hostName);
std::stringstream sspid;
#ifdef __vxworks
sspid << taskIdSelf();
#else
sspid << getpid();
#endif
result->getSubField<PVString>("process")->put(sspid.str());
char timeText[64];
epicsTimeToStrftime(timeText, 64, "%Y-%m-%dT%H:%M:%S.%03f", &m_serverContext->getStartTime());
result->getSubField<PVString>("startTime")->put(timeText);
return result;
}
else
@@ -531,14 +577,28 @@ Structure::const_shared_pointer ServerRPCService::channelListStructure =
addArray("value", pvString)->
createStructure();
Structure::const_shared_pointer ServerRPCService::infoStructure =
getFieldCreate()->createFieldBuilder()->
add("process", pvString)->
add("startTime", pvString)->
add("version", pvString)->
add("implLang", pvString)->
add("host", pvString)->
// add("os", pvString)->
// add("arch", pvString)->
// add("CPUs", pvInt)->
createStructure();
std::string ServerRPCService::helpString =
"pvAccess server RPC service.\n"
"arguments:\n"
"\tstring op\toperation to execute\n"
"\n"
"\toperations:\n"
"\t\tinfo\t\treturns some information about the server\n"
"\t\tchannels\treturns a list of 'static' channels the server can provide\n"
"\t\t\t (no arguments)\n"
// "\t\t\t (no arguments)\n"
"\n";
std::string ServerCreateChannelHandler::SERVER_CHANNEL_NAME = "server";

View File

@@ -40,9 +40,12 @@ ServerContextImpl::ServerContextImpl():
_channelProviderRegistry(),
_channelProviderNames(PVACCESS_DEFAULT_PROVIDER),
_channelProviders(),
_beaconServerStatusProvider()
_beaconServerStatusProvider(),
_startTime()
{
epicsTimeGetCurrent(&_startTime);
// TODO maybe there is a better place for this (when there will be some factory)
epicsSignalInstallSigAlarmIgnore ();
epicsSignalInstallSigPipeIgnore ();
@@ -674,6 +677,12 @@ void ServerContextImpl::newServerDetected()
// not used
}
epicsTimeStamp& ServerContextImpl::getStartTime()
{
return _startTime;
}
std::map<std::string, std::tr1::shared_ptr<SecurityPlugin> >& ServerContextImpl::getSecurityPlugins()
{
return SecurityPluginRegistry::instance().getServerSecurityPlugins();

View File

@@ -92,6 +92,8 @@ public:
*/
virtual void dispose() = 0;
virtual epicsTimeStamp& getStartTime() = 0;
// ************************************************************************** //
// **************************** [ Plugins ] ********************************* //
// ************************************************************************** //
@@ -146,6 +148,9 @@ public:
BlockingUDPTransport::shared_pointer getLocalMulticastTransport();
epicsTimeStamp& getStartTime();
/**
* Version.
*/
@@ -440,6 +445,9 @@ private:
void destroyAllTransports();
Configuration::shared_pointer configuration;
epicsTimeStamp _startTime;
};
epicsShareExtern ServerContext::shared_pointer startPVAServer(