ContextLocal added
This commit is contained in:
@ -10,46 +10,27 @@
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#include <pv/channelProviderLocal.h>
|
||||
#include <pv/serverContext.h>
|
||||
|
||||
#include <pv/exampleDatabase.h>
|
||||
|
||||
using namespace std;
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvDatabase;
|
||||
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
PVDatabasePtr master = PVDatabase::getMaster();
|
||||
ChannelProviderLocalPtr channelProvider = getChannelProviderLocal();
|
||||
ExampleDatabase::create();
|
||||
ServerContext::shared_pointer ctx =
|
||||
startPVAServer(PVACCESS_ALL_PROVIDERS,0,true,true);
|
||||
cout << "exampleDatabase\n";
|
||||
PVStringArrayPtr pvNames = master->getRecordNames();
|
||||
cout << "recordNames" << endl << *pvNames << endl;
|
||||
string str;
|
||||
while(true) {
|
||||
cout << "Type exit to stop: \n";
|
||||
getline(cin,str);
|
||||
if(str.compare("exit")==0) break;
|
||||
|
||||
}
|
||||
ctx->destroy();
|
||||
epicsThreadSleep(1.0);
|
||||
channelProvider->destroy();
|
||||
ContextLocal::shared_pointer contextLocal = ContextLocal::create();
|
||||
contextLocal->start();
|
||||
|
||||
cout << "pvAccess server exampleDatabase running..." << endl;
|
||||
epics::pvData::PVStringArrayPtr pvNames = PVDatabase::getMaster()->getRecordNames();
|
||||
cout << "Hosted records: " << endl << *pvNames << endl;
|
||||
|
||||
contextLocal->waitForExit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -10,24 +10,15 @@
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
#include <pv/recordList.h>
|
||||
#include <pv/powerSupply.h>
|
||||
#include <pv/traceRecord.h>
|
||||
#include <pv/channelProviderLocal.h>
|
||||
#include <pv/serverContext.h>
|
||||
|
||||
using namespace std;
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvDatabase;
|
||||
@ -36,37 +27,30 @@ using namespace epics::pvDatabase;
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
PVDatabasePtr master = PVDatabase::getMaster();
|
||||
ChannelProviderLocalPtr channelProvider = getChannelProviderLocal();
|
||||
|
||||
PVRecordPtr pvRecord;
|
||||
bool result(false);
|
||||
bool result = false;
|
||||
string recordName;
|
||||
|
||||
recordName = "powerSupply";
|
||||
PVStructurePtr pv = createPowerSupply();
|
||||
pvRecord = PowerSupply::create(recordName,pv);
|
||||
result = master->addRecord(pvRecord);
|
||||
cout << "result of addRecord " << recordName << " " << result << endl;
|
||||
|
||||
recordName = "traceRecordPGRPC";
|
||||
pvRecord = TraceRecord::create(recordName);
|
||||
result = master->addRecord(pvRecord);
|
||||
if(!result) cout<< "record " << recordName << " not added" << endl;
|
||||
if (!result) cout<< "record " << recordName << " not added" << endl;
|
||||
|
||||
recordName = "laptoprecordListPGRPC";
|
||||
pvRecord = RecordListRecord::create(recordName);
|
||||
result = master->addRecord(pvRecord);
|
||||
if(!result) cout<< "record " << recordName << " not added" << endl;
|
||||
ServerContext::shared_pointer pvaServer =
|
||||
startPVAServer(PVACCESS_ALL_PROVIDERS,0,true,true);
|
||||
cout << "powerSupply\n";
|
||||
string str;
|
||||
while(true) {
|
||||
cout << "Type exit to stop: \n";
|
||||
getline(cin,str);
|
||||
if(str.compare("exit")==0) break;
|
||||
if (!result) cout<< "record " << recordName << " not added" << endl;
|
||||
|
||||
ContextLocal::shared_pointer contextLocal = ContextLocal::create();
|
||||
contextLocal->start(true);
|
||||
|
||||
}
|
||||
pvaServer->shutdown();
|
||||
epicsThreadSleep(1.0);
|
||||
pvaServer->destroy();
|
||||
channelProvider->destroy();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -10,24 +10,15 @@
|
||||
|
||||
/* Author: Marty Kraimer */
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
|
||||
#include <pv/standardField.h>
|
||||
#include <pv/standardPVField.h>
|
||||
#include <pv/exampleServer.h>
|
||||
#include <pv/traceRecord.h>
|
||||
#include <pv/recordList.h>
|
||||
#include <pv/channelProviderLocal.h>
|
||||
#include <pv/serverContext.h>
|
||||
|
||||
using namespace std;
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvDatabase;
|
||||
@ -36,38 +27,35 @@ using namespace epics::exampleServer;
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
PVDatabasePtr master = PVDatabase::getMaster();
|
||||
ChannelProviderLocalPtr channelProvider = getChannelProviderLocal();
|
||||
PVRecordPtr pvRecord;
|
||||
bool result(false);
|
||||
bool result = false;
|
||||
string recordName;
|
||||
|
||||
recordName = "exampleServer";
|
||||
pvRecord = ExampleServer::create(recordName);
|
||||
result = master->addRecord(pvRecord);
|
||||
if(!result) cout<< "record " << recordName << " not added" << endl;
|
||||
|
||||
recordName = "traceRecordPGRPC";
|
||||
pvRecord = TraceRecord::create(recordName);
|
||||
result = master->addRecord(pvRecord);
|
||||
if(!result) cout<< "record " << recordName << " not added" << endl;
|
||||
|
||||
recordName = "laptoprecordListPGRPC";
|
||||
pvRecord = RecordListRecord::create(recordName);
|
||||
result = master->addRecord(pvRecord);
|
||||
if(!result) cout<< "record " << recordName << " not added" << endl;
|
||||
ServerContext::shared_pointer pvaServer =
|
||||
startPVAServer(PVACCESS_ALL_PROVIDERS,0,true,true);
|
||||
|
||||
|
||||
ContextLocal::shared_pointer contextLocal = ContextLocal::create();
|
||||
contextLocal->start();
|
||||
|
||||
PVStringArrayPtr pvNames = master->getRecordNames();
|
||||
shared_vector<const string> names = pvNames->view();
|
||||
for(size_t i=0; i<names.size(); ++i) cout << names[i] << endl;
|
||||
string str;
|
||||
while(true) {
|
||||
cout << "Type exit to stop: \n";
|
||||
getline(cin,str);
|
||||
if(str.compare("exit")==0) break;
|
||||
|
||||
}
|
||||
pvaServer->shutdown();
|
||||
epicsThreadSleep(1.0);
|
||||
pvaServer->destroy();
|
||||
channelProvider->destroy();
|
||||
contextLocal->waitForExit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -88,12 +88,12 @@ ChannelProviderLocal::ChannelProviderLocal()
|
||||
|
||||
ChannelProviderLocal::~ChannelProviderLocal()
|
||||
{
|
||||
cout << "~ChannelProviderLocal()" << endl;
|
||||
// TODO should I call destroy() here
|
||||
destroy();
|
||||
}
|
||||
|
||||
void ChannelProviderLocal::destroy()
|
||||
{
|
||||
cout << "ChannelProviderLocal::destroy()" << endl;
|
||||
Lock xx(mutex);
|
||||
if(beingDestroyed) return;
|
||||
beingDestroyed = true;
|
||||
@ -172,4 +172,47 @@ Channel::shared_pointer ChannelProviderLocal::createChannel(
|
||||
return Channel::shared_pointer();
|
||||
}
|
||||
|
||||
|
||||
ContextLocal::shared_pointer ContextLocal::create()
|
||||
{
|
||||
return ContextLocal::shared_pointer(new ContextLocal());
|
||||
}
|
||||
|
||||
void ContextLocal::start(bool _waitForExit)
|
||||
{
|
||||
m_context = startPVAServer(
|
||||
PVACCESS_ALL_PROVIDERS,
|
||||
0,
|
||||
true,
|
||||
true);
|
||||
|
||||
if (_waitForExit)
|
||||
waitForExit();
|
||||
}
|
||||
|
||||
void ContextLocal::waitForExit()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
std::cout << "Type 'exit' to stop: ";
|
||||
std::string input;
|
||||
std::cin >> input;
|
||||
if (input == "exit")
|
||||
break;
|
||||
}
|
||||
|
||||
destroy();
|
||||
}
|
||||
|
||||
void ContextLocal::destroy()
|
||||
{
|
||||
if (m_context)
|
||||
m_context->destroy();
|
||||
}
|
||||
|
||||
ContextLocal::ContextLocal()
|
||||
{
|
||||
m_channelProvider = getChannelProviderLocal();
|
||||
}
|
||||
|
||||
}}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <pv/pvCopy.h>
|
||||
#include <pv/pvAccess.h>
|
||||
#include <pv/status.h>
|
||||
#include <pv/serverContext.h>
|
||||
|
||||
#ifdef channelProviderLocalEpicsExportSharedSymbols
|
||||
# define epicsExportSharedSymbols
|
||||
@ -399,7 +400,44 @@ private:
|
||||
epics::pvData::Mutex mutex;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief A pvAccess server context that provides
|
||||
* remote access to a local channel providers (i.e. pvDatabase records).
|
||||
*/
|
||||
class epicsShareClass ContextLocal
|
||||
{
|
||||
|
||||
public:
|
||||
POINTER_DEFINITIONS(ContextLocal);
|
||||
|
||||
static shared_pointer create();
|
||||
|
||||
/**
|
||||
* Start the context thread.
|
||||
* After this is called clients can connect to the server.
|
||||
* @param waitForExit In true then waitForExit() method is called after the server is started.
|
||||
*/
|
||||
void start(bool waitForExit = false);
|
||||
|
||||
/**
|
||||
* Waits for "exit" to be entered on standard input and calls destroy() before returning.
|
||||
*/
|
||||
void waitForExit();
|
||||
|
||||
/**
|
||||
* This destroys the context.
|
||||
* All clients will be disconnected.
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
ContextLocal();
|
||||
|
||||
ChannelProviderLocalPtr m_channelProvider;
|
||||
epics::pvAccess::ServerContext::shared_pointer m_context;
|
||||
};
|
||||
|
||||
|
||||
}}
|
||||
#endif /* CHANNELPROVIDERLOCAL_H */
|
||||
|
Reference in New Issue
Block a user