本文整理汇总了C++中Program::Devices方法的典型用法代码示例。如果您正苦于以下问题:C++ Program::Devices方法的具体用法?C++ Program::Devices怎么用?C++ Program::Devices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Program
的用法示例。
在下文中一共展示了Program::Devices方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetProcessStatus
string GetProcessStatus( string query, string id )
{
// string programName = GetRequestProgramName( query );
Program* program = ProgramManager::Instance()->GetRunningProgram( atoi( id.c_str() ) );
string jsonDescr;
if( program == NULL ) {
// the program is not started
jsonDescr += "{\"Status\":\"NotAvailable\"}";
return jsonDescr;
}
string deviceStatus;
string propertyName = "Value";
DeviceParameter value;
char deviceId[16];
string status = "not set";
char buffer[32];
string deviceIp = WebServer::Instance()->Ip();
int devicePort = WebServer::Instance()->Port();
sprintf( buffer, "%d", devicePort );
string processResource = "http://" + deviceIp + ":" + (string)buffer + "/Processes/" + id;
string projectResource = "http://" + deviceIp + ":" + (string)buffer + "/Projects/" + id;
string operation = GetProgramStatusOperation;
jsonDescr = "{\"ResourceId\":\"" + processResource + "\",\"ProjectResourceId\":\"" + projectResource + "\",\"Devices\":[";
string deviceUrl;
string propertyUrl;
list<BaseDevice*>::iterator it;
for( it = program->Devices()->begin(); it != program->Devices()->end(); it++ )
{
value = ( *it )->GetParameter( propertyName );
if ( value.IsInitialized() == true )
{
status = value.StringValue();
}
else
{
continue;
}
sprintf( deviceId, "%d", (*it)->Id() );
// sprintf( status, "%d", statusValue );
deviceUrl = processResource + "/Devices/" + (string)deviceId;
deviceStatus = "{\"ResourceId\":\"" + deviceUrl + "\",\"Properties\":[{\"ResourceId\":\"" + deviceUrl + "/Properties/" + propertyName + "\",\"devkey\":\"" +
propertyName + "\",\"devtype\":\"int\",\"devvalue\":\"" + status + "\"}]},";
jsonDescr += deviceStatus;
}
jsonDescr = jsonDescr.substr( 0, jsonDescr.length() - 1 ); // remove the last comma
jsonDescr += "],\"Status\":\"Running\"}";
return jsonDescr;
}
示例2: GetDevicePropery
string GetDevicePropery( string query )
{
string result = "";
int programId = atoi( strtok( (char*)query.c_str(), "." ) );
int deviceId = atoi( strtok( NULL, "." ) );
char* propertyName = strtok( NULL, "." );
string propertyValue = "";
Program* program = ProgramManager::Instance()->GetRunningProgram( programId );
if ( program == NULL )
{
cout<< "Program with id: "<<programId<<" is not started.\n";
EventLogger::Instance()->WriteVerbose( "Program with id: %d is not started.", programId );
return "";
}
list<BaseDevice*>::iterator it;
for ( it = program->Devices()->begin(); it != program->Devices()->end(); it++ )
{
if ( ( *it )->Id() == deviceId )
{
//we have found the device we want -> set the Property we need
DeviceParameter value = ( *it )->GetParameter( propertyName );
if( value.IsInitialized() == true )
{
propertyValue = Convert::ToString( value.Value(), value.AgilartType() );
}
else
{
propertyValue = "0";
}
if ( result != "" )
result += "-";
result += propertyValue;
break;
}
}
return result;
}
示例3: SetScreenDeviceStatus
void SetScreenDeviceStatus( string query )
{
char *key = strtok( (char*)query.c_str(), "=" );
char *value = strtok( NULL, ";" );
int programId = atoi( strtok( key, "." ) );
int deviceId = atoi( strtok( NULL, "." ) );
char* propertyName = strtok( NULL, "." );
bool isFound = false;
Program* program = ProgramManager::Instance()->GetRunningProgram( programId );
if ( program == NULL )
{
cout<< "Program with id: "<<programId<<" is not started.\n";
EventLogger::Instance()->WriteVerbose("Program with id: %d is not started.", programId );
return;
}
list<BaseDevice*>::iterator it;
for ( it = program->Devices()->begin(); it != program->Devices()->end(); it++ )
{
if ( ( *it )->Id() == deviceId )
{
isFound = true;
//we have found the device we want -> set the Property we need
void* statusValue = new string( value );
( *it )->SetParameter( propertyName, statusValue );
break;
}
}
if ( isFound == false )
{
cout<< "Device with id: "<<deviceId<<" is not available in program with id: "<<programId<<endl;
EventLogger::Instance()->WriteVerbose("Device with id: %d is not available in program with id: %d", deviceId, programId );
}
}