From 620f0f06814964990e7d3501fa9391f78e797cfb Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Wed, 3 Nov 2010 16:07:20 +0100 Subject: [PATCH] ChannelAccessFactory implemented and tested --- QtC-pvAccess.files | 1 + pvAccessApp/Makefile | 2 +- pvAccessApp/client/ChannelAccessFactory.cpp | 53 +- pvAccessApp/client/pvAccess.h | 809 +++++++++--------- pvAccessApp/testClient/Makefile | 12 + .../testClient/testChannelAccessFactory.cpp | 87 ++ 6 files changed, 566 insertions(+), 398 deletions(-) create mode 100644 pvAccessApp/testClient/Makefile create mode 100644 pvAccessApp/testClient/testChannelAccessFactory.cpp diff --git a/QtC-pvAccess.files b/QtC-pvAccess.files index c98bb09..e0ea208 100644 --- a/QtC-pvAccess.files +++ b/QtC-pvAccess.files @@ -1,2 +1,3 @@ pvAccessApp/client/pvAccess.h pvAccessApp/client/ChannelAccessFactory.cpp +pvAccessApp/testClient/testChannelAccessFactory.cpp diff --git a/pvAccessApp/Makefile b/pvAccessApp/Makefile index e441c44..b35d36c 100644 --- a/pvAccessApp/Makefile +++ b/pvAccessApp/Makefile @@ -1,6 +1,6 @@ TOP = .. include $(TOP)/configure/CONFIG -DIRS += client #server +DIRS += client testClient #server #DIRS += localImpl remoteClientImpl remoteServerImpl #DIRS += localImplTest remoteImplTest include $(TOP)/configure/RULES_DIRS diff --git a/pvAccessApp/client/ChannelAccessFactory.cpp b/pvAccessApp/client/ChannelAccessFactory.cpp index 97cb401..bb2c17d 100644 --- a/pvAccessApp/client/ChannelAccessFactory.cpp +++ b/pvAccessApp/client/ChannelAccessFactory.cpp @@ -1,24 +1,61 @@ /*ChannelAccessFactory.cpp*/ #include +#include #include "pvAccess.h" #include "pvData.h" #include "factory.h" +#include +#include namespace epics { namespace pvAccess { static ChannelAccess* channelAccess = 0; +static Mutex channelProviderMutex = Mutex(); - ChannelAccess * getChannelAccess() { - static Mutex mutex = Mutex(); - Lock guard(&mutex); +typedef std::map ChannelProviderMap; +static ChannelProviderMap channelProviders; - if(channelAccess==0){ - //channelAccess = new ChannelAccessImpl(); - } - return channelAccess; - } + +class ChannelAccessImpl : public ChannelAccess, public NoDefaultMethods { + public: + + ChannelProvider* getProvider(String providerName) { + Lock guard(&channelProviderMutex); + return channelProviders[providerName]; + } + + std::vector* getProviderNames() { + Lock guard(&channelProviderMutex); + std::vector* providers = new std::vector(); + for (ChannelProviderMap::const_iterator i = channelProviders.begin(); + i != channelProviders.end(); i++) + providers->push_back(i->first); + + return providers; + } +}; + +ChannelAccess * getChannelAccess() { + static Mutex mutex = Mutex(); + Lock guard(&mutex); + + if(channelAccess==0){ + channelAccess = new ChannelAccessImpl(); + } + return channelAccess; +} + +void registerChannelProvider(ChannelProvider *channelProvider) { + Lock guard(&channelProviderMutex); + channelProviders[channelProvider->getProviderName()] = channelProvider; +} + +void unregisterChannelProvider(ChannelProvider *channelProvider) { + Lock guard(&channelProviderMutex); + channelProviders.erase(channelProvider->getProviderName()); +} }} diff --git a/pvAccessApp/client/pvAccess.h b/pvAccessApp/client/pvAccess.h index 424e613..81f4a23 100644 --- a/pvAccessApp/client/pvAccess.h +++ b/pvAccessApp/client/pvAccess.h @@ -2,6 +2,7 @@ #ifndef PVACCESS_H #define PVACCESS_H #include +#include using namespace epics::pvData; @@ -91,378 +92,392 @@ namespace epics { namespace pvAccess { /** - * Base interface for all channel requests. - * @author mse - */ + * Base interface for all channel requests. + * @author mse + */ class ChannelRequest /* : public Destroyable */ { }; /** - * Request to put and get Array Data. - * The data is either taken from or put in the PVArray returned by ChannelArrayRequester.channelArrayConnect. - * @author mrk - * - */ + * Request to put and get Array Data. + * The data is either taken from or put in the PVArray returned by ChannelArrayRequester.channelArrayConnect. + * @author mrk + * + */ class ChannelArray : public ChannelRequest{ - public: + public: + /** - * put to the remote array. - * @param lastRequest Is this the last request. - * @param offset The offset in the remote array, i.e. the PVArray returned by ChannelArrayRequester.channelArrayConnect. - * @param count The number of elements to put. - */ + * put to the remote array. + * @param lastRequest Is this the last request. + * @param offset The offset in the remote array, i.e. the PVArray returned by ChannelArrayRequester.channelArrayConnect. + * @param count The number of elements to put. + */ virtual void putArray(bool lastRequest, int offset, int count); + /** - * get from the remote array. - * @param lastRequest Is this the last request. - * @param offset The offset in the remote array, i.e. the PVArray returned by ChannelArrayRequester.channelArrayConnect. - * @param count The number of elements to get. - */ + * get from the remote array. + * @param lastRequest Is this the last request. + * @param offset The offset in the remote array, i.e. the PVArray returned by ChannelArrayRequester.channelArrayConnect. + * @param count The number of elements to get. + */ virtual void getArray(bool lastRequest, int offset, int count); + /** - * Set the length and/or the capacity. - * @param lastRequest Is this the last request. - * @param length The new length. -1 means do not change. - * @param capacity The new capacity. -1 means do not change. - */ + * Set the length and/or the capacity. + * @param lastRequest Is this the last request. + * @param length The new length. -1 means do not change. + * @param capacity The new capacity. -1 means do not change. + */ virtual void setLength(bool lastRequest, int length, int capacity); }; /** - * The requester for a ChannelArray. - * @author mrk - * - */ + * The requester for a ChannelArray. + * @author mrk + * + */ class ChannelArrayRequester : public Requester { - public: + public: + /** - * The client and server have both completed the createChannelArray request. - * @param status Completion status. - * @param channelArray The channelArray interface or null if the request failed. - * @param pvArray The PVArray that holds the data. - */ + * The client and server have both completed the createChannelArray request. + * @param status Completion status. + * @param channelArray The channelArray interface or null if the request failed. + * @param pvArray The PVArray that holds the data. + */ virtual void channelArrayConnect(Status *status,ChannelArray *channelArray,PVArray *pvArray) = 0; + /** - * The request is done. This is always called with no locks held. - * @param status Completion status. - */ + * The request is done. This is always called with no locks held. + * @param status Completion status. + */ virtual void putArrayDone(Status *status) = 0; + /** - * The request is done. This is always called with no locks held. - * @param status Completion status. - */ + * The request is done. This is always called with no locks held. + * @param status Completion status. + */ virtual void getArrayDone(Status *status) = 0; + /** - * The request is done. This is always called with no locks held. - * @param status Completion status. - */ + * The request is done. This is always called with no locks held. + * @param status Completion status. + */ virtual void setLengthDone(Status *status) = 0; }; /** - * @author mrk - * - */ + * @author mrk + * + */ class ChannelFind { - public: + public: virtual ChannelProvider* getChannelProvider() = 0; virtual void cancelChannelFind() = 0; }; /** - * @author mrk - * - */ + * @author mrk + * + */ class ChannelFindRequester { - public: + public: + /** - * @param status Completion status. - */ + * @param status Completion status. + */ virtual void channelFindResult(Status *status,ChannelFind *channelFind,bool wasFound) = 0; }; - /** - * Request to get data from a channel. - * @author mrk - * - */ + * Request to get data from a channel. + * @author mrk + * + */ class ChannelGet : public ChannelRequest { - public: + public: + /** - * Get data from the channel. - * This fails if the request can not be satisfied. - * If it fails ChannelGetRequester.getDone is called before get returns. - * @param lastRequest Is this the last request? - */ + * Get data from the channel. + * This fails if the request can not be satisfied. + * If it fails ChannelGetRequester.getDone is called before get returns. + * @param lastRequest Is this the last request? + */ virtual void get(bool lastRequest) = 0; }; /** - * Requester for channelGet. - * @author mrk - * - */ + * Requester for channelGet. + * @author mrk + * + */ class ChannelGetRequester : public Requester { - public: + public: + /** - * The client and server have both completed the createChannelGet request. - * @param status Completion status. - * @param channelGet The channelGet interface or null if the request failed. - * @param pvStructure The PVStructure that holds the data. - * @param bitSet The bitSet for that shows what data has changed. - */ + * The client and server have both completed the createChannelGet request. + * @param status Completion status. + * @param channelGet The channelGet interface or null if the request failed. + * @param pvStructure The PVStructure that holds the data. + * @param bitSet The bitSet for that shows what data has changed. + */ virtual void channelGetConnect(Status *status,ChannelGet *channelGet,PVStructure *pvStructure,BitSet *bitSet) = 0; + /** - * The request is done. This is always called with no locks held. - * @param status Completion status. - */ + * The request is done. This is always called with no locks held. + * @param status Completion status. + */ virtual void getDone(Status *status) = 0; }; - - - - /** - * ChannelProcess - request that a channel be processed.. - * @author mrk - * - */ + * ChannelProcess - request that a channel be processed.. + * @author mrk + * + */ class ChannelProcess : public ChannelRequest { - public: + public: + /** - * Issue a process request. - * This fails if the request can not be satisfied. - * If it fails the channelProcessRequester.processDone is called before process returns. - * @param lastRequest Is this the last request? - */ + * Issue a process request. + * This fails if the request can not be satisfied. + * If it fails the channelProcessRequester.processDone is called before process returns. + * @param lastRequest Is this the last request? + */ virtual void process(bool lastRequest) = 0; }; /** - * Requester for channelProcess. - * @author mrk - * - */ + * Requester for channelProcess. + * @author mrk + * + */ class ChannelProcessRequester : public Requester { - public: + public: + /** - * The client and server have both completed the createChannelProcess request. - * @param status Completion status. - * @param channelProcess The channelProcess interface or null if the client could not become - * the record processor. - */ + * The client and server have both completed the createChannelProcess request. + * @param status Completion status. + * @param channelProcess The channelProcess interface or null if the client could not become + * the record processor. + */ virtual void channelProcessConnect(Status *status,ChannelProcess *channelProcess) = 0; + /** - * The process request is done. This is always called with no locks held. - * @param status Completion status. - */ + * The process request is done. This is always called with no locks held. + * @param status Completion status. + */ virtual void processDone(Status *status) = 0; }; - - - /** - * Interface for a channel access put request. - * @author mrk - * - */ + * Interface for a channel access put request. + * @author mrk + * + */ class ChannelPut : public ChannelRequest { - public: + public: + /** - * Put data to a channel. - * This fails if the request can not be satisfied. - * If it fails ChannelPutRequester.putDone is called before put returns. - * @param lastRequest Is this the last request? - */ + * Put data to a channel. + * This fails if the request can not be satisfied. + * If it fails ChannelPutRequester.putDone is called before put returns. + * @param lastRequest Is this the last request? + */ virtual void put(bool lastRequest) = 0; + /** - * Get the current data. - */ + * Get the current data. + */ virtual void get() = 0; }; /** - * Requester for ChannelPut. - * @author mrk - * - */ + * Requester for ChannelPut. + * @author mrk + * + */ class ChannelPutRequester : public Requester { - public: + public: + /** - * The client and server have both processed the createChannelPut request. - * @param status Completion status. - * @param channelPut The channelPut interface or null if the request failed. - * @param pvStructure The PVStructure that holds the data. - * @param bitSet The bitSet for that shows what data has changed. - */ + * The client and server have both processed the createChannelPut request. + * @param status Completion status. + * @param channelPut The channelPut interface or null if the request failed. + * @param pvStructure The PVStructure that holds the data. + * @param bitSet The bitSet for that shows what data has changed. + */ virtual void channelPutConnect(Status *status,ChannelPut *channelPut,PVStructure *pvStructure,BitSet *bitSet) = 0; + /** - * The request is done. This is always called with no locks held. - * @param status Completion status. - */ + * The request is done. This is always called with no locks held. + * @param status Completion status. + */ virtual void putDone(Status *status) = 0; + /** - * The get request is done. This is always called with no locks held. - * @param status Completion status. - */ + * The get request is done. This is always called with no locks held. + * @param status Completion status. + */ virtual void getDone(Status *status) = 0; }; - - - - /** - * Channel access put/get request. - * The put is performed first, followed optionally by a process request, and then by a get request. - * @author mrk - * - */ + * Channel access put/get request. + * The put is performed first, followed optionally by a process request, and then by a get request. + * @author mrk + * + */ class ChannelPutGet : public ChannelRequest { - public: + public: + /** - * Issue a put/get request. If process was requested when the ChannelPutGet was created this is a put, process, get. - * This fails if the request can not be satisfied. - * If it fails ChannelPutGetRequester.putDone is called before putGet returns. - * @param lastRequest Is this the last request? - */ + * Issue a put/get request. If process was requested when the ChannelPutGet was created this is a put, process, get. + * This fails if the request can not be satisfied. + * If it fails ChannelPutGetRequester.putDone is called before putGet returns. + * @param lastRequest Is this the last request? + */ virtual void putGet(bool lastRequest) = 0; + /** - * Get the put PVStructure. The record will not be processed. - */ + * Get the put PVStructure. The record will not be processed. + */ virtual void getPut() = 0; + /** - * Get the get PVStructure. The record will not be processed. - */ + * Get the get PVStructure. The record will not be processed. + */ virtual void getGet() = 0; }; + /** - * Requester for ChannelPutGet. - * @author mrk - * - */ + * Requester for ChannelPutGet. + * @author mrk + * + */ class ChannelPutGetRequester : public Requester { - public: + public: + /** - * The client and server have both completed the createChannelPutGet request. - * @param status Completion status. - * @param channelPutGet The channelPutGet interface or null if the request failed. - * @param pvPutStructure The PVStructure that holds the putData. - * @param pvGetStructure The PVStructure that holds the getData. - */ + * The client and server have both completed the createChannelPutGet request. + * @param status Completion status. + * @param channelPutGet The channelPutGet interface or null if the request failed. + * @param pvPutStructure The PVStructure that holds the putData. + * @param pvGetStructure The PVStructure that holds the getData. + */ virtual void channelPutGetConnect(Status *status,ChannelPutGet *channelPutGet, PVStructure *pvPutStructure,PVStructure *pvGetStructure) = 0; /** - * The putGet request is done. This is always called with no locks held. - * @param status Completion status. - */ + * The putGet request is done. This is always called with no locks held. + * @param status Completion status. + */ virtual void putGetDone(Status *status) = 0; + /** - * The getPut request is done. This is always called with no locks held. - * @param status Completion status. - */ + * The getPut request is done. This is always called with no locks held. + * @param status Completion status. + */ virtual void getPutDone(Status *status) = 0; + /** - * The getGet request is done. This is always called with no locks held. - * @param status Completion status. - */ + * The getGet request is done. This is always called with no locks held. + * @param status Completion status. + */ virtual void getGetDone(Status *status) = 0; }; - - - - - /** - * Requester for channelGet. - * @author mrk - * - */ + * Requester for channelGet. + * @author mrk + * + */ class ChannelRPC : public ChannelRequest { - public: + public: + /** - * Issue an RPC request to the channel. - * This fails if the request can not be satisfied. - * @param lastRequest Is this the last request? - */ + * Issue an RPC request to the channel. + * This fails if the request can not be satisfied. + * @param lastRequest Is this the last request? + */ virtual void request(bool lastRequest) = 0; }; + /** - * Requester for channelGet. - * @author mrk - * - */ + * Requester for channelGet. + * @author mrk + * + */ class ChannelRPCRequester : public Requester { - public: + public: + /** - * The client and server have both completed the createChannelGet request. - * @param status Completion status. - * @param channelRPC The channelRPC interface or null if the request failed. - * @param pvArgument The argument structure for an RPC request. - * @param bitSet The bitSet for argument changes. - */ + * The client and server have both completed the createChannelGet request. + * @param status Completion status. + * @param channelRPC The channelRPC interface or null if the request failed. + * @param pvArgument The argument structure for an RPC request. + * @param bitSet The bitSet for argument changes. + */ virtual void channelRPCConnect(Status *status,ChannelRPC *channelRPC,PVStructure *pvArgument,BitSet *bitSet) = 0; + /** - * The request is done. This is always called with no locks held. - * @param status Completion status. - * @param pvResponse The response data for the RPC request. - */ + * The request is done. This is always called with no locks held. + * @param status Completion status. + * @param pvResponse The response data for the RPC request. + */ virtual void requestDone(Status *status,PVStructure *pvResponse) = 0; }; - /** - * Requester for a getStructure request. - * @author mrk - * - */ + * Requester for a getStructure request. + * @author mrk + * + */ class GetFieldRequester : public Requester { - public: + public: + /** - * The client and server have both completed the getStructure request. - * @param status Completion status. - * @param field The Structure for the request. - */ + * The client and server have both completed the getStructure request. + * @param status Completion status. + * @param field The Structure for the request. + */ virtual void getDone(Status *status,Field *field) = 0; }; - /** - * Listener for connect state changes. - * @author mrk - * - */ + * Listener for connect state changes. + * @author mrk + * + */ class ChannelRequester : public Requester { - public: + public: + /** - * A channel has been created. This may be called multiple times if there are multiple providers. - * @param status Completion status. - * @param channel The channel. - */ + * A channel has been created. This may be called multiple times if there are multiple providers. + * @param status Completion status. + * @param channel The channel. + */ virtual void channelCreated(Status* status, Channel *channel) = 0; + /** - * A channel connection state change has occurred. - * @param c The channel. - * @param connectionState The new connection state. - */ + * A channel connection state change has occurred. + * @param c The channel. + * @param connectionState The new connection state. + */ virtual void channelStateChange(Channel *c, ConnectionState connectionState) = 0; }; @@ -472,139 +487,153 @@ namespace epics { namespace pvAccess { class MonitorRequester; /** - * Interface for accessing a channel. - * A channel is created via a call to ChannelAccess.createChannel(String channelName). - * @author mrk - * @author msekoranja - */ + * Interface for accessing a channel. + * A channel is created via a call to ChannelAccess.createChannel(String channelName). + * @author mrk + * @author msekoranja + */ class Channel : public Requester { - public: + public: /** - * Get the the channel provider of this channel. - * @return The channel provider. - */ + * Get the the channel provider of this channel. + * @return The channel provider. + */ virtual ChannelProvider* getProvider() = 0; + /** - * Returns the channel's remote address, e.g. "/192.168.1.101:5064" or "#C0 S1". - * @return the channel's remote address. - **/ + * Returns the channel's remote address, e.g. "/192.168.1.101:5064" or "#C0 S1". + * @return the channel's remote address. + **/ virtual String getRemoteAddress() = 0; + /** - * Returns the connection state of this channel. - * @return the ConnectionState value. - **/ + * Returns the connection state of this channel. + * @return the ConnectionState value. + **/ virtual ConnectionState getConnectionState() = 0; + /** - * Destroy the channel. It will not honor any further requests. - */ + * Destroy the channel. It will not honor any further requests. + */ virtual void destroy() = 0; + /** - * Get the channel name. - * @return The name. - */ + * Get the channel name. + * @return The name. + */ virtual String getChannelName() = 0; + /** - * Get the channel requester. - * @return The requester. - */ + * Get the channel requester. + * @return The requester. + */ virtual ChannelRequester* getChannelRequester() = 0; + /** - * Is the channel connected? - * @return (false,true) means (not, is) connected. - */ + * Is the channel connected? + * @return (false,true) means (not, is) connected. + */ virtual bool isConnected() = 0; + /** - * Get a Field which describes the subField. - * GetFieldRequester.getDone is called after both client and server have processed the getField request. - * This is for clients that want to introspect a PVRecord via channel access. - * @param requester The requester. - * @param subField The name of the subField. - * If this is null or an empty string the returned Field is for the entire record. - */ + * Get a Field which describes the subField. + * GetFieldRequester.getDone is called after both client and server have processed the getField request. + * This is for clients that want to introspect a PVRecord via channel access. + * @param requester The requester. + * @param subField The name of the subField. + * If this is null or an empty string the returned Field is for the entire record. + */ virtual void getField(GetFieldRequester *requester,String subField) = 0; + /** - * Get the access rights for a field of a PVStructure created via a call to createPVStructure. - * MATEJ Channel access can store this info via auxInfo. - * @param pvField The field for which access rights is desired. - * @return The access rights. - */ + * Get the access rights for a field of a PVStructure created via a call to createPVStructure. + * MATEJ Channel access can store this info via auxInfo. + * @param pvField The field for which access rights is desired. + * @return The access rights. + */ virtual AccessRights getAccessRights(PVField *pvField) = 0; + /** - * Create a ChannelProcess. - * ChannelProcessRequester.channelProcessReady is called after both client and server are ready for - * the client to make a process request. - * @param channelProcessRequester The interface for notifying when this request is complete - * and when channel completes processing. - * @param pvRequest Additional options (e.g. triggering). - * @return ChannelProcess instance. - */ + * Create a ChannelProcess. + * ChannelProcessRequester.channelProcessReady is called after both client and server are ready for + * the client to make a process request. + * @param channelProcessRequester The interface for notifying when this request is complete + * and when channel completes processing. + * @param pvRequest Additional options (e.g. triggering). + * @return ChannelProcess instance. + */ virtual ChannelProcess* createChannelProcess( ChannelProcessRequester *channelProcessRequester, PVStructure *pvRequest) = 0; + /** - * Create a ChannelGet. - * ChannelGetRequester.channelGetReady is called after both client and server are ready for - * the client to make a get request. - * @param channelGetRequester The interface for notifying when this request is complete - * and when a channel get completes. - * @param pvRequest A structure describing the desired set of fields from the remote PVRecord. - * This has the same form as a pvRequest to PVCopyFactory.create. - * @return ChannelGet instance. - */ + * Create a ChannelGet. + * ChannelGetRequester.channelGetReady is called after both client and server are ready for + * the client to make a get request. + * @param channelGetRequester The interface for notifying when this request is complete + * and when a channel get completes. + * @param pvRequest A structure describing the desired set of fields from the remote PVRecord. + * This has the same form as a pvRequest to PVCopyFactory.create. + * @return ChannelGet instance. + */ virtual ChannelGet* createChannelGet( ChannelGetRequester *channelGetRequester, PVStructure *pvRequest) = 0; + /** - * Create a ChannelPut. - * ChannelPutRequester.channelPutReady is called after both client and server are ready for - * the client to make a put request. - * @param channelPutRequester The interface for notifying when this request is complete - * and when a channel get completes. - * @param pvRequest A structure describing the desired set of fields from the remote PVRecord. - * This has the same form as a pvRequest to PVCopyFactory.create. - * @return ChannelPut instance. - */ + * Create a ChannelPut. + * ChannelPutRequester.channelPutReady is called after both client and server are ready for + * the client to make a put request. + * @param channelPutRequester The interface for notifying when this request is complete + * and when a channel get completes. + * @param pvRequest A structure describing the desired set of fields from the remote PVRecord. + * This has the same form as a pvRequest to PVCopyFactory.create. + * @return ChannelPut instance. + */ virtual ChannelPut* createChannelPut( ChannelPutRequester *channelPutRequester, PVStructure *pvRequest) = 0; + /** - * Create a ChannelPutGet. - * ChannelPutGetRequester.channelPutGetReady is called after both client and server are ready for - * the client to make a putGet request. - * @param channelPutGetRequester The interface for notifying when this request is complete - * and when a channel get completes. - * @param pvRequest A structure describing the desired set of fields from the remote PVRecord. - * This has the same form as a pvRequest to PVCopyFactory.create. - * @return ChannelPutGet instance. - */ + * Create a ChannelPutGet. + * ChannelPutGetRequester.channelPutGetReady is called after both client and server are ready for + * the client to make a putGet request. + * @param channelPutGetRequester The interface for notifying when this request is complete + * and when a channel get completes. + * @param pvRequest A structure describing the desired set of fields from the remote PVRecord. + * This has the same form as a pvRequest to PVCopyFactory.create. + * @return ChannelPutGet instance. + */ virtual ChannelPutGet* createChannelPutGet( ChannelPutGetRequester *channelPutGetRequester, PVStructure *pvRequest) = 0; + /** - * Create a ChannelRPC (Remote Procedure Call). - * @param channelRPCRequester The requester. - * @param pvRequest Request options. - * @return ChannelRPC instance. - */ + * Create a ChannelRPC (Remote Procedure Call). + * @param channelRPCRequester The requester. + * @param pvRequest Request options. + * @return ChannelRPC instance. + */ virtual ChannelRPC* createChannelRPC(ChannelRPCRequester *channelRPCRequester,PVStructure *pvRequest) = 0; + /** - * Create a Monitor. - * @param monitorRequester The requester. - * @param pvRequest A structure describing the desired set of fields from the remote PVRecord. - * This has the same form as a pvRequest to PVCopyFactory.create. - * @return Monitor instance. - */ + * Create a Monitor. + * @param monitorRequester The requester. + * @param pvRequest A structure describing the desired set of fields from the remote PVRecord. + * This has the same form as a pvRequest to PVCopyFactory.create. + * @return Monitor instance. + */ virtual Monitor* createMonitor( MonitorRequester *monitorRequester, PVStructure *pvRequest) = 0; /** - * Create a ChannelArray. - * @param channelArrayRequester The ChannelArrayRequester - * @param pvRequest Additional options (e.g. triggering). - * @return ChannelArray instance. - */ + * Create a ChannelArray. + * @param channelArrayRequester The ChannelArrayRequester + * @param pvRequest Additional options (e.g. triggering). + * @return ChannelArray instance. + */ virtual ChannelArray* createChannelArray( ChannelArrayRequester *channelArrayRequester, PVStructure *pvRequest) = 0; @@ -612,36 +641,38 @@ namespace epics { namespace pvAccess { - - /** - * Interface for locating channel providers. - * @author mrk - * - */ + * Interface for locating channel providers. + * @author mrk + * + */ class ChannelAccess { - public: + public: + /** - * Get the provider with the specified name. - * @param providerName The name of the provider. - * @return The interface for the provider or null if the provider is not known. - */ + * Get the provider with the specified name. + * @param providerName The name of the provider. + * @return The interface for the provider or null if the provider is not known. + */ virtual ChannelProvider* getProvider(String providerName) = 0; + /** - * Get a array of the names of all the known providers. - * @return The names. - */ - virtual String* getProviderNames() = 0; + * Get a array of the names of all the known providers. + * @return The names. Be sure to delete vector instance. + */ + virtual std::vector* getProviderNames() = 0; }; extern ChannelAccess * getChannelAccess(); + extern void registerChannelProvider(ChannelProvider *channelProvider); + extern void unregisterChannelProvider(ChannelProvider *channelProvider); /** - * Interface implemented by code that can provide access to the record - * to which a channel connects. - * @author mrk - * - */ + * Interface implemented by code that can provide access to the record + * to which a channel connects. + * @author mrk + * + */ class ChannelProvider { public: @@ -659,90 +690,90 @@ namespace epics { namespace pvAccess { static const short PRIORITY_OPI = PRIORITY_MIN; /** - * Terminate. - */ + * Terminate. + */ virtual void destroy() = 0; + /** - * Get the provider name. - * @return The name. - */ + * Get the provider name. + * @return The name. + */ virtual String getProviderName() = 0; + /** - * Find a channel. - * @param channelName The channel name. - * @param channelFindRequester The requester. - * @return An interface for the find. - */ + * Find a channel. + * @param channelName The channel name. + * @param channelFindRequester The requester. + * @return An interface for the find. + */ virtual ChannelFind* channelFind(String channelName,ChannelFindRequester *channelFindRequester) = 0; + /** - * Create a channel. - * @param channelName The name of the channel. - * @param channelRequester The requester. - * @param priority channel priority, must be PRIORITY_MIN <= priority <= PRIORITY_MAX. - * @return Channel instance. If channel does not exist null is returned and channelRequester notified. - */ + * Create a channel. + * @param channelName The name of the channel. + * @param channelRequester The requester. + * @param priority channel priority, must be PRIORITY_MIN <= priority <= PRIORITY_MAX. + * @return Channel instance. If channel does not exist null is returned and channelRequester notified. + */ virtual Channel* createChannel(String channelName,ChannelRequester *channelRequester,short priority) = 0; + /** - * Create a channel. - * @param channelName The name of the channel. - * @param channelRequester The requester. - * @param priority channel priority, must be PRIORITY_MIN <= priority <= PRIORITY_MAX. - * @param address address (or list of addresses) where to look for a channel. Implementation independed string. - * @return Channel instance. If channel does not exist null is returned and channelRequester notified. - */ + * Create a channel. + * @param channelName The name of the channel. + * @param channelRequester The requester. + * @param priority channel priority, must be PRIORITY_MIN <= priority <= PRIORITY_MAX. + * @param address address (or list of addresses) where to look for a channel. Implementation independed string. + * @return Channel instance. If channel does not exist null is returned and channelRequester notified. + */ virtual Channel* createChannel(String channelName,ChannelRequester *channelRequester,short priority,String address) = 0; }; - // TODO - class Version; - /** - * The class representing a CA Client Context. - * @author Matej Sekoranja - * @version $Id: ClientContext.java,v 1.1 2010/05/03 14:45:40 mrkraimer Exp $ - */ + * The class representing a CA Client Context. + * @author Matej Sekoranja + */ class ClientContext { - public: + public: /** - * Get context implementation version. - * @return version of the context implementation. - */ - virtual Version getVersion() = 0; + * Get context implementation version. + * @return version of the context implementation. + */ + virtual String getVersion() = 0; /** - * Initialize client context. This method is called immediately after instance construction (call of constructor). - */ + * Initialize client context. This method is called immediately after instance construction (call of constructor). + */ virtual void initialize() = 0; /** - * Get channel provider implementation. - * @return the channel provider. - */ + * Get channel provider implementation. + * @return the channel provider. + */ virtual ChannelProvider* getProvider() = 0; /** - * Prints detailed information about the context to the standard output stream. - */ + * Prints detailed information about the context to the standard output stream. + */ virtual void printInfo() = 0; /** - * Prints detailed information about the context to the specified output stream. - * @param out the output stream. - */ + * Prints detailed information about the context to the specified output stream. + * @param out the output stream. + */ virtual void printInfo(StringBuilder out) = 0; /** - * Clear all resources attached to this Context - * @throws IllegalStateException if the context has been destroyed. - */ + * Clear all resources attached to this Context + * @throws IllegalStateException if the context has been destroyed. + */ virtual void destroy() = 0; /** - * Dispose (destroy) server context. - * This calls destroy() and silently handles all exceptions. - */ + * Dispose (destroy) server context. + * This calls destroy() and silently handles all exceptions. + */ virtual void dispose() = 0; }; diff --git a/pvAccessApp/testClient/Makefile b/pvAccessApp/testClient/Makefile new file mode 100644 index 0000000..3d5e261 --- /dev/null +++ b/pvAccessApp/testClient/Makefile @@ -0,0 +1,12 @@ +TOP=../.. + +include $(TOP)/configure/CONFIG + +PROD_HOST += testChannelAccessFactory +testChannelAccessFactory_SRCS += testChannelAccessFactory.cpp +testChannelAccessFactory_LIBS += pvAccessClient Com + +include $(TOP)/configure/RULES +#---------------------------------------- +# ADD RULES AFTER THIS LINE + diff --git a/pvAccessApp/testClient/testChannelAccessFactory.cpp b/pvAccessApp/testClient/testChannelAccessFactory.cpp new file mode 100644 index 0000000..a791a9e --- /dev/null +++ b/pvAccessApp/testClient/testChannelAccessFactory.cpp @@ -0,0 +1,87 @@ +/* testChannelAccessFactory.cpp */ +/* Author: Matej Sekoranja Date: 2010.11.03 */ + +#include +#include +#include +#include +#include +#include "pvAccess.h" + + +#include + +using namespace epics::pvAccess; + +class DummyChannelProvider : public ChannelProvider { +private: + String m_name; +public: + DummyChannelProvider(String name) : m_name(name) {}; + void destroy() {}; + String getProviderName() { return m_name; }; + + ChannelFind* channelFind(String channelName,ChannelFindRequester *channelFindRequester) + { return 0; } + + Channel* createChannel(String channelName,ChannelRequester *channelRequester,short priority) + { return 0; } + + Channel* createChannel(String channelName,ChannelRequester *channelRequester,short priority,String address) + { return 0; } +}; + + + +void testChannelAccessFactory() { + printf("testChannelAccessFactory... "); + + ChannelAccess* ca = getChannelAccess(); + assert(ca); + + // empty + std::vector* providers = ca->getProviderNames(); + assert(providers); + assert(providers->size() == 0); + delete providers; + + // register 2 + ChannelProvider* cp1 = new DummyChannelProvider("dummy1"); + registerChannelProvider(cp1); + + ChannelProvider* cp2 = new DummyChannelProvider("dummy2"); + registerChannelProvider(cp2); + + providers = ca->getProviderNames(); + assert(providers); + assert(providers->size() == 2); + assert(providers->at(0) == "dummy1"); + assert(providers->at(1) == "dummy2"); + + assert(ca->getProvider("dummy1") == cp1); + assert(ca->getProvider("dummy2") == cp2); + + delete providers; + + + // unregister first + unregisterChannelProvider(cp1); + + providers = ca->getProviderNames(); + assert(providers); + assert(providers->size() == 1); + assert(providers->at(0) == "dummy2"); + assert(ca->getProvider("dummy2") == cp2); + delete providers; + + printf("PASSED\n"); + +} + +int main(int argc,char *argv[]) +{ + testChannelAccessFactory(); + return(0); +} + +