Example #1
0
			inline const string& getDeviceDriverName( ) const
			{ return devDriver.getValue(); }
Example #2
0
			inline const string& getFirmwareLevel( ) const
			{ return mFirmwareLevel.getValue(); }
Example #3
0
			inline const string& getManufacturer( ) const
			{ return mManufacturer.getValue(); }
Example #4
0
			inline const string& getFRU( ) const
			{ return mFRU.getValue(); }
Example #5
0
			inline const string& getFirmwareVersion( ) const
			{ return mFirmwareVersion.getValue(); }
Example #6
0
			inline const string& getSerialNumber( ) const
			{ return mSerialNumber.getValue(); }
Example #7
0
			inline const string& getPartNumber( ) const
			{ return mPartNumber.getValue(); }
Example #8
0
			inline const string& getRecordType( ) const
			{ return mRecordType.getValue( ); }
Example #9
0
			//The Get Value methods
			inline const string& getDescription( ) const
			{ return mDescription.getValue(); }
Example #10
0
			/**
			 * getClassNode
			 * @brief Returns the full path for the device in the /sys/class
			 */
			inline string getClassNode( )
			{
				return mDevClass.getValue();
			}
Example #11
0
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++)
		{		
			CJobHandler *  _jobHandler = new CJobHandler((AgentMgr * ) this, (Job*) cmsd.jobs->at(i).get(),&cmsd,_cellHandlers);
			_jobHandlers.push_back(_jobHandler);
			_group->create_thread(boost::bind(&CJobHandler::Cycle, _jobHandler));
		}
*/
		_nSpinup =  config.GetSymbolValue("CONFIG.Spinup",0).toNumber<int>();
		if(_nSpinup)
		{
			_devicesAgentCfg.SetDevicesXmlFolder(_devicexmlpath);
			_devicesAgentCfg.SetHttpPort(80);
			_devicesAgentCfg.SetXmlFile("Devices1.xml");
			_devicesAgentCfg.SetCfgFile("Agent1.cfg");
			_devicesAgentCfg.SetDestinationFolder(::ExeDirectory());
			_devicesAgentCfg.SpawnProcess();
			spinup.StartSpinUp();
		}
		start();
	}
	catch(...) {}

	return 0;
}
string XmlPrinter::printSample (const unsigned int       instanceId,
                                const unsigned int       bufferSize,
                                const uint64_t           nextSeq,
                                const uint64_t           firstSeq,
                                const uint64_t           lastSeq,
                                ComponentEventPtrArray & results
                                )
{
    xmlTextWriterPtr writer;
    xmlBufferPtr     buf;
    string           ret;

    try
    {
        THROW_IF_XML2_NULL(buf = xmlBufferCreate( ));
        THROW_IF_XML2_NULL(writer = xmlNewTextWriterMemory(buf, 0));
        THROW_IF_XML2_ERROR(xmlTextWriterSetIndent(writer, 1));
        THROW_IF_XML2_ERROR(xmlTextWriterSetIndentString(writer, BAD_CAST "  "));

        initXmlDoc(writer, eSTREAMS,
                   instanceId,
                   bufferSize,
                   0, 0,
                   nextSeq,
                   firstSeq,
                   lastSeq);

        THROW_IF_XML2_ERROR(xmlTextWriterStartElement(writer, BAD_CAST "Streams"));

        // Sort the vector by category.
        if ( results.size( ) > 1 )
        {
            dlib::qsort_array<ComponentEventPtrArray, EventComparer>(results, 0, results.size( ) - 1, EventCompare);
        }

        Device *   lastDevice    = NULL;
        Component *lastComponent = NULL;
        int        lastCategory  = -1;

        for ( unsigned int i = 0; i < results.size( ); i++ )
        {
            ComponentEventPtr result    = results[i];
            DataItem *        dataItem  = result->getDataItem( );
            Component *       component = dataItem->getComponent( );
            Device *          device    = component->getDevice( );

            if ( device != lastDevice )
            {
                if ( lastDevice != NULL )
                {
                    THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // DeviceStream
                }
                lastDevice = device;

                if ( lastComponent != NULL )
                {
                    THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // ComponentStream
                }
                lastComponent = NULL;

                if ( lastCategory != -1 )
                {
                    THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // Category
                }
                lastCategory = -1;
                addDeviceStream(writer, device);
            }

            if ( component != lastComponent )
            {
                if ( lastComponent != NULL )
                {
                    THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // ComponentStream
                }
                lastComponent = component;

                if ( lastCategory != -1 )
                {
                    THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // Category
                }
                lastCategory = -1;
                addComponentStream(writer, component);
            }

            if ( lastCategory != dataItem->getCategory( ) )
            {
                if ( lastCategory != -1 )
                {
                    THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // Category
                }
                lastCategory = dataItem->getCategory( );
                addCategory(writer, dataItem->getCategory( ));
            }

            addEvent(writer, result);
        }

        if ( lastCategory != -1 )
        {
            THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // Category
        }

        if ( lastDevice != NULL )
        {
            THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // DeviceStream
        }

        if ( lastComponent != NULL )
        {
            THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // ComponentStream
        }
        THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer));     // Streams
        THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer));     // MTConnectStreams
        THROW_IF_XML2_ERROR(xmlTextWriterEndDocument(writer));

        xmlFreeTextWriter(writer);
        ret = (string) ( (char *) buf->content );
        xmlBufferFree(buf);
    }
    catch ( string error )
    {
        if ( buf != NULL )
        {
            xmlBufferFree(buf);
        }

        if ( writer != NULL )
        {
            xmlFreeTextWriter(writer);
        }
        sLogger << dlib::LERROR << "printProbe: " << error;
    }
    catch ( ... )
    {
        if ( buf != NULL )
        {
            xmlBufferFree(buf);
        }

        if ( writer != NULL )
        {
            xmlFreeTextWriter(writer);
        }
        sLogger << dlib::LERROR << "printProbe: unknown error";
    }

    return ret;
}