ServerChannelImpl
This commit is contained in:
117
pvAccessApp/server/serverChannelImpl.cpp
Normal file
117
pvAccessApp/server/serverChannelImpl.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* serverChannelImpl.cpp
|
||||
*/
|
||||
|
||||
#include "serverChannelImpl.h"
|
||||
|
||||
|
||||
namespace epics { namespace pvAccess {
|
||||
|
||||
ServerChannelImpl::ServerChannelImpl(Channel* channel, int32 cid,
|
||||
int32 sid, epics::pvData::PVField* securityToken):
|
||||
_channel(channel),
|
||||
_cid(cid),
|
||||
_sid(cid)
|
||||
{
|
||||
if (channel == NULL)
|
||||
{
|
||||
THROW_BASE_EXCEPTION("non null local channel required");
|
||||
}
|
||||
}
|
||||
|
||||
Channel* ServerChannelImpl::getChannel()
|
||||
{
|
||||
return _channel;
|
||||
}
|
||||
|
||||
int32 ServerChannelImpl::getCID()
|
||||
{
|
||||
return _cid;
|
||||
}
|
||||
|
||||
int32 ServerChannelImpl::getSID()
|
||||
{
|
||||
return _sid;
|
||||
}
|
||||
|
||||
int16 ServerChannelImpl::getAccessRights()
|
||||
{
|
||||
//TODO implement
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ServerChannelImpl::registerRequest(const int32 id, Destroyable* const request)
|
||||
{
|
||||
if (request == NULL)
|
||||
{
|
||||
THROW_BASE_EXCEPTION("request == null");
|
||||
}
|
||||
|
||||
Lock guard(_mutex);
|
||||
_requests[id] = request;
|
||||
}
|
||||
|
||||
void ServerChannelImpl::unregisterRequest(const int32 id)
|
||||
{
|
||||
Lock guard(_mutex);
|
||||
std::map<int32, epics::pvData::Destroyable*>::iterator iter = _requests.find(id);
|
||||
if(iter != _requests.end())
|
||||
{
|
||||
_requests.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
Destroyable* ServerChannelImpl::getRequest(const int32 id)
|
||||
{
|
||||
std::map<int32, epics::pvData::Destroyable*>::iterator iter = _requests.find(id);
|
||||
if(iter != _requests.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ServerChannelImpl::destroy()
|
||||
{
|
||||
Lock guard(_mutex);
|
||||
if (_destroyed) return;
|
||||
|
||||
_destroyed = true;
|
||||
|
||||
// destroy all requests
|
||||
destroyAllRequests();
|
||||
|
||||
// TODO make impl that does shares channels (and does ref counting)!!!
|
||||
// try catch?
|
||||
static_cast<ChannelImpl*>(_channel)->destroy();
|
||||
}
|
||||
|
||||
void ServerChannelImpl::printInfo()
|
||||
{
|
||||
printInfo(stdout);
|
||||
}
|
||||
|
||||
void ServerChannelImpl::printInfo(FILE *fd)
|
||||
{
|
||||
fprintf(fd,"CLASS : %s\n", typeid(*this).name());
|
||||
fprintf(fd,"CHANNEL : %s\n", typeid(*_channel).name());
|
||||
}
|
||||
|
||||
void ServerChannelImpl::destroyAllRequests()
|
||||
{
|
||||
Lock guard(_mutex);
|
||||
|
||||
// resource allocation optimization
|
||||
if (_requests.size() == 0)
|
||||
return;
|
||||
|
||||
std::map<int32, epics::pvData::Destroyable*>::iterator iter = _requests.begin();
|
||||
for(; iter != _requests.end(); iter++)
|
||||
{
|
||||
iter->second->destroy();
|
||||
}
|
||||
_requests.clear();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
134
pvAccessApp/server/serverChannelImpl.h
Normal file
134
pvAccessApp/server/serverChannelImpl.h
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* serverChannel.h
|
||||
*/
|
||||
|
||||
#ifndef SERVERCHANNEL_H_
|
||||
#define SERVERCHANNEL_H_
|
||||
|
||||
#include "remote.h"
|
||||
#include "clientContextImpl.h"
|
||||
|
||||
#include <destroyable.h>
|
||||
|
||||
namespace epics {
|
||||
namespace pvAccess {
|
||||
|
||||
class ServerChannelImpl : public ServerChannel
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create server channel for given process variable.
|
||||
* @param channel local channel.
|
||||
* @param cid channel CID.
|
||||
* @param sid channel SID.
|
||||
* @param securityToken security token.
|
||||
*/
|
||||
ServerChannelImpl(Channel* channel, int32 cid, int32 sid, epics::pvData::PVField* securityToken);
|
||||
/*
|
||||
* Destructor.
|
||||
*/
|
||||
~ServerChannelImpl() {};
|
||||
|
||||
/**
|
||||
* Get local channel.
|
||||
* @return local channel.
|
||||
*/
|
||||
Channel* getChannel();
|
||||
|
||||
/**
|
||||
* Get channel CID.
|
||||
* @return channel CID.
|
||||
*/
|
||||
int32 getCID();
|
||||
|
||||
/**
|
||||
* Get channel SID.
|
||||
* @return channel SID.
|
||||
*/
|
||||
int32 getSID();
|
||||
|
||||
/**
|
||||
* Get access rights (bit-mask encoded).
|
||||
* @see AccessRights
|
||||
* @return bit-mask encoded access rights.
|
||||
*/
|
||||
int16 getAccessRights();
|
||||
|
||||
/**
|
||||
* Register request
|
||||
* @param id request ID.
|
||||
* @param request request to be registered.
|
||||
*/
|
||||
void registerRequest(int32 id, Destroyable* const request);
|
||||
|
||||
/**
|
||||
* Unregister request.
|
||||
* @param id request ID.
|
||||
*/
|
||||
void unregisterRequest(int32 id);
|
||||
|
||||
/**
|
||||
* Get request by its ID.
|
||||
* @param id request ID.
|
||||
* @return request with given ID, <code>null</code> if there is no request with such ID.
|
||||
*/
|
||||
Destroyable* getRequest(int32 id);
|
||||
|
||||
/**
|
||||
* Destroy server channel.
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
/**
|
||||
* Prints detailed information about the process variable to the standard output stream.
|
||||
*/
|
||||
void printInfo();
|
||||
|
||||
/**
|
||||
* Prints detailed information about the process variable to the specified output
|
||||
* stream.
|
||||
* @param fd the output stream.
|
||||
*/
|
||||
void printInfo(FILE *fd);
|
||||
private:
|
||||
/**
|
||||
* Local channel.
|
||||
*/
|
||||
Channel* _channel;
|
||||
|
||||
/**
|
||||
* Channel CID.
|
||||
*/
|
||||
int32 _cid;
|
||||
|
||||
/**
|
||||
* Channel SID.
|
||||
*/
|
||||
int32 _sid;
|
||||
|
||||
/**
|
||||
* Requests.
|
||||
*/
|
||||
std::map<int32, epics::pvData::Destroyable*> _requests;
|
||||
|
||||
/**
|
||||
* Destroy state.
|
||||
*/
|
||||
boolean _destroyed;
|
||||
|
||||
/**
|
||||
* Mutex
|
||||
*/
|
||||
epics::pvData::Mutex _mutex;
|
||||
|
||||
/**
|
||||
* Destroy all registered requests.
|
||||
*/
|
||||
void destroyAllRequests();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* SERVERCHANNEL_H_ */
|
||||
Reference in New Issue
Block a user