Example #1
0
 void ServiceControl(int offset, const std::string& operation, int ranking)
 {
     if (0 <= offset && offset <= 3)
     {
         if (operation == "register")
         {
             if (!servregs[offset])
             {
                 std::stringstream servicename;
                 servicename << SERVICE << offset;
                 InterfaceMap ifm;
                 ifm.insert(std::make_pair(servicename.str(), static_cast<void*>(this)));
                 ServiceProperties props;
                 props.insert(std::make_pair(ServiceConstants::SERVICE_RANKING(), Any(ranking)));
                 servregs[offset] = mc->RegisterService(ifm, props);
             }
         }
         if (operation == "unregister")
         {
             if (servregs[offset])
             {
                 ServiceRegistrationU sr1 = servregs[offset];
                 sr1.Unregister();
                 servregs[offset] = 0;
             }
         }
     }
 }
Example #2
0
ServiceProperties ctkServices::createServiceProperties(const ServiceProperties& in,
                                                       const QStringList& classes,
                                                       long sid)
{
  static qlonglong nextServiceID = 1;
  ServiceProperties props = in;

  if (!classes.isEmpty())
  {
    props.insert(ctkPluginConstants::OBJECTCLASS, classes);
  }

  props.insert(ctkPluginConstants::SERVICE_ID, sid != -1 ? sid : nextServiceID++);

  return props;
}
Example #3
0
bool LDAPExpr::Evaluate( const ServiceProperties& p, bool matchCase ) const
{
  if ((d->m_operator & SIMPLE) != 0)
  {
    Any propVal;
    ServiceProperties::const_iterator it = p.find(d->m_attrName);
    if (it != p.end() && (matchCase ? d->m_attrName == (std::string)it->first : true))
    {
      propVal = it->second;
    }
    return Compare(propVal, d->m_operator, d->m_attrValue);
  }
  else
  { // (d->m_operator & COMPLEX) != 0
    switch (d->m_operator)
    {
    case AND:
      for (std::size_t i = 0; i < d->m_args.size(); i++)
      {
        if (!d->m_args[i].Evaluate(p, matchCase))
          return false;
      }
      return true;
    case OR:
      for (std::size_t i = 0; i < d->m_args.size(); i++)
      {
        if (d->m_args[i].Evaluate(p, matchCase))
          return true;
      }
      return false;
    case NOT:
      return !d->m_args[0].Evaluate(p, matchCase);
    default:
      return false; // Cannot happen
    }
  }
}
Example #4
0
ServiceProxy::ServiceProxy( unsigned int PeerId, SimpleString eHostName, int eControlPort, ServiceProperties& ServiceProps )
	: ControlClient(PeerId)
{
	SimpleString TmpString;
	VariableAttribute * VarAtt;
	InOutputAttribute * IOAtt;
	int Pos;
	unsigned int Port;

	HostName	= eHostName;
	ControlPort	= eControlPort;
	FullDescription = false;

	// Is the description
	TmpString = ServiceProps["desc"].GetValue();
	//if ( ServiceProps.IsDefined( "name" ) )
	//{
	//	OmiscidError( "Warning, forced fallback for '%s' (%s).\n",
	//		ServiceProps[NameString].GetValue().GetStr(), ServiceProps["id"].GetValue().GetStr() );
	//}
	//else
	//{
	//	OmiscidError( "Warning, forced fallback for %8.8x.\n", PeerId );
	//}
	//if ( TmpString == "forced fallback" )
	// OmiscidTrace( "Working on'%s' (%s).\n",
	//	 ServiceProps[ControlServer::NameString].GetValue().GetStr(), ServiceProps["id"].GetValue().GetStr() );

	if ( TmpString == "full" )
	{
		FullDescription = true;
	}

	for( Pos = 0; Pos <  ServiceProps.GetNumberOfProperties(); Pos++ )
	{
		ServiceProperty& LocalProp = ServiceProps.GetProperty(Pos);

		if ( LocalProp.GetName() == "desc" )
		{
			continue;
		}

		// SimpleString TmpName = LocalProp.GetName();

		// Parse property
		TmpString = LocalProp.GetValue();
		char * TmpChar = (char*)TmpString.GetStr();
		switch( TmpString[0] )
		{
			// Work on Variables
			case 'c':
				if ( TmpString.GetLength() <= 2 || TmpString[1] != '/' )
				{
					FullDescription = false;
					continue;
				}

				// Ok, something like c/...
				VarAtt = new OMISCID_TLM VariableAttribute( LocalProp.GetName() );
				if ( VarAtt == NULL )
				{
					FullDescription = false;
					continue;
				}
				VarAtt->SetValue( TmpChar+2 );
				VarAtt->SetAccessConstant();
				listVariableName.Add( LocalProp.GetName() );
				listVariableAttr.Add( VarAtt );
				break;

			case 'r':
				if ( TmpString.GetLength() != 1 )
				{
					FullDescription = false;
					continue;
				}

				// Ok, something like r/...
				VarAtt = new OMISCID_TLM VariableAttribute( LocalProp.GetName() );
				if ( VarAtt == NULL )
				{
					FullDescription = false;
					continue;
				}
				VarAtt->SetAccessRead();
				listVariableName.Add( LocalProp.GetName() );
				listVariableAttr.Add( VarAtt );
				break;

			case 'w':
				if ( TmpString.GetLength() != 1 )
				{
					FullDescription = false;
					continue;
				}

				// Ok, something like w/...
				VarAtt = new OMISCID_TLM VariableAttribute( LocalProp.GetName() );
				if ( VarAtt == NULL )
				{
					FullDescription = false;
					continue;
				}
				VarAtt->SetAccessReadWrite();
				listVariableName.Add( LocalProp.GetName() );
				listVariableAttr.Add( VarAtt );
				break;

			// Work on Connectors
			case 'i':
				if ( TmpString[1] != '/' || TmpString[2] < '0' || TmpString[2] > '9' )
				{
					FullDescription = false;
					continue;
				}

				// Check if we've got a correct port
				Port = 0;
				Port = atoi(TmpChar+2);
				if ( Port == 0 || Port >= 0x0000ffff )
				{
					FullDescription = false;
					continue;
				}

				IOAtt = new OMISCID_TLM InOutputAttribute( LocalProp.GetName(), NULL, AnInput );
				if ( IOAtt == NULL )
				{
					FullDescription = false;
					continue;
				}
				IOAtt->SetTcpPort( (unsigned short)Port );
				listInputName.Add( LocalProp.GetName() );
				listInputAttr.Add( IOAtt );
				break;

			case 'o':
				if ( TmpString[1] != '/' || TmpString[2] < '0' || TmpString[2] > '9' )
				{
					FullDescription = false;
					continue;
				}

				// Check if we've got a correct port
				Port = 0;
				Port = atoi(TmpChar+2);
				if ( Port == 0 || Port >= 0x0000ffff )
				{
					FullDescription = false;
					continue;
				}

				IOAtt = new OMISCID_TLM InOutputAttribute( LocalProp.GetName(), NULL, AnOutput );
				if ( IOAtt == NULL )
				{
					FullDescription = false;
					continue;
				}
				IOAtt->SetTcpPort( (unsigned short)Port );
				listOutputName.Add( LocalProp.GetName() );
				listOutputAttr.Add( IOAtt );
				break;

			case 'd':
				if ( TmpString[1] != '/' || TmpString[2] < '0' || TmpString[2] > '9' )
				{
					FullDescription = false;
					continue;
				}

				// Check if we've got a correct port
				Port = 0;
				Port = atoi(TmpChar+2);
				if ( Port == 0 || Port >= 0x0000ffff )
				{
					FullDescription = false;
					continue;
				}

				IOAtt = new OMISCID_TLM InOutputAttribute( LocalProp.GetName(), NULL, AnInOutput );
				if ( IOAtt == NULL )
				{
					FullDescription = false;
					continue;
				}
				IOAtt->SetTcpPort( (unsigned short)Port );
				listInOutputName.Add( LocalProp.GetName() );
				listInOutputAttr.Add( IOAtt );
				break;

			default:
				FullDescription = false;
				continue;
		}
	}

	//if ( FullDescription == false )
	//{
	//	UpdateDescription();
	//}
}