本文整理汇总了C++中DataItem::addObserver方法的典型用法代码示例。如果您正苦于以下问题:C++ DataItem::addObserver方法的具体用法?C++ DataItem::addObserver怎么用?C++ DataItem::addObserver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataItem
的用法示例。
在下文中一共展示了DataItem::addObserver方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: thread
int AgentMgr::thread(int aArgc, const char *aArgv[])
{
//sLogger << LENTRY << "MTConnect Agent Service Started " << nowtimestamp() << "\n";
#ifdef OBSERVER
// Test out observer functionality
Device *dev = getDeviceByName(devicename);
DataItem *di = dev->getDeviceDataItem("Xabs");
di->addObserver(new BusyObserver("Xabs", di));
#endif
try{
clear();
_group= new boost::thread_group();
_agent = new AgentConfiguration();
int nPort=7878;
std::string cfgfile;
if(aArgc > 0)
{
cfgfile= aArgv[0];
}
else
cfgfile= ::ExeDirectory() + "VirtualFactoryTestbed.xml";
char result[ MAX_PATH ];
std::string path( result, GetModuleFileName( NULL, result, MAX_PATH ) );
std::string inifile = path.substr(0,path.find_last_of(".")) + ".ini";
if(GetFileAttributesA(inifile.c_str())== INVALID_FILE_ATTRIBUTES)
throw std::exception(("No " + inifile + " file").c_str());
config.load(inifile);
_devicexmlpath = config.GetSymbolValue("CONFIG.DevicesFolder", ::ExeDirectory()).c_str();
_devicefile = config.GetSymbolValue("CONFIG.DevicesFile", "Devices.xml").c_str();
_cfgfile = config.GetSymbolValue("CONFIG.CfgFile","Agent.cfg").c_str();
_httpPort = config.GetSymbolValue("CONFIG.HttpPort","81").toNumber<int>();
_debugSimulation = config.GetSymbolValue("CONFIG.DebugSimulation","1").toNumber<int>();
_cmdAgentCfg.SetDevicesXmlFolder(_devicexmlpath);
_cmdAgentCfg.SetHttpPort(_httpPort);
_cmdAgentCfg.SetXmlFile(_devicefile);
_cmdAgentCfg.SetCfgFile(_cfgfile);
_cmdAgentCfg.SetDestinationFolder(::ExeDirectory());
SetCurrentDirectory(::ExeDirectory().c_str()); // fixes Agent file lookup issue
// if( GetFileAttributesA(cfgfile.c_str())!= INVALID_FILE_ATTRIBUTES)
{
for(int i=0 ; i< cmsd.resources->size(); i++)
{
Resource * r = (Resource *) cmsd.resources->at(i).get();
std::string name = (LPCSTR) r->name;
if(name.empty() || name == "None") // something wrong
continue;
_cmdAgentCfg.AddDevice(name, // M1, M2
"Command", // lookup name in devices.xml folder
"", // no ip required for SHDR, will talk directly to agent
"0"); //writing to agent will be done using thread pointer not SHDR
_devicesAgentCfg.AddDevice(name, // M1, M2
"Generic", // lookup name in devices.xml folder
"127.0.0.1",
StdStringFormat("%d", nPort++));
//spinup.AddDevice("herbie",
// name,
// GetHostName(),
// nPort-1,
// GetHostName() + ":81"
// );
CResourceHandler * _resourceHandler = new CResourceHandler(_agent, this,r, &cmsd);
_resourceHandlers.push_back(_resourceHandler);
_resourceHandlers.back()->Configure( config,(LPCSTR) r->identifier, name, "Command", "127.0.0.1:80/"+name,_devicexmlpath);
}
for(int i=0 ; i< cmsd.cells->size(); i++)
{
Cell * c = (Cell *) cmsd.cells->at(i).get();
std::string name = (LPCSTR) c->name;
CCellHandler * _cellHandler = new CCellHandler((AgentMgr * ) this, c,&cmsd);
_cellHandlers.push_back(_cellHandler);
for(int j=0; j< c-> resourceIds.size(); j++)
{
CResourceHandler * r = findResource((LPCSTR) c-> resourceIds[j]) ;
if(r!=NULL)
_cellHandler->_resources.push_back(r);
}
}
}
_cmdAgentCfg.Start(_agent);
::Sleep(1000);
/*for(int i=0; i< _resourceHandlers.size(); i++)
_group->create_thread(boost::bind(&CResourceHandler::Thread, _resourceHandlers[i]));
*/
/* for(int i=0 ; i< cmsd.jobs->size(); i++)
{
//.........这里部分代码省略.........