ContextLocal added

This commit is contained in:
Matej Sekoranja
2015-02-24 10:59:30 +01:00
parent c0694e2d69
commit e79c70c74c
5 changed files with 114 additions and 80 deletions

View File

@@ -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();
}
}}