Exemple #1
0
void CFellow::PublishAndSubscribe()
{
    if (ms_rtiAmb)
    {
        RTI::AttributeHandleSet *fellowAttrs;
        try
        {
            fellowAttrs = RTI::AttributeHandleSetFactory::create(3);
            fellowAttrs->add(ms_hFellowName);
            fellowAttrs->add(ms_hFellowColor);
            fellowAttrs->add(ms_hFellowPortrait);
        }
        catch (RTI::Exception& e)
        {
            AfxMessageBox((CString)e._name);
        }

        try
        {
            ms_rtiAmb->subscribeObjectClassAttributes(ms_hFellow, *fellowAttrs);
            ms_rtiAmb->publishObjectClass(ms_hFellow, *fellowAttrs);
        }
        catch (RTI::Exception& e)
        {
            AfxMessageBox((CString)e._name);
        }

        fellowAttrs->empty();
        delete fellowAttrs;
    }
}
ProvideAttributeValueUpdatePR::ProvideAttributeValueUpdatePR (RTI::ObjectHandle oid,
	const RTI::AttributeHandleSet & attr)
	: objid (oid), size (attr.size ())
	{
	handleSet = new RTI::AttributeHandle [size];
	if (handleSet == NULL)
		{
		cerr << "Unable to create array of attribute handles, can't process attribute update request" << endl;
		size = 0;
		return;
		}
	
	for (int i = 0; i < size; i++)
		{
		handleSet[i] = attr.getHandle (i);
		}
	}
/*
 * This method will inform the RTI about the types of data that the federate will
 * be creating, and the types of data we are interested in hearing about as other
 * federates produce it.
 */
void ExampleCPPFederate::publishAndSubscribe()
{
	////////////////////////////////////////////
	// publish all attributes of ObjectRoot.A //
	////////////////////////////////////////////
	// before we can register instance of the object class ObjectRoot.A and
	// update the values of the various attributes, we need to tell the RTI
	// that we intend to publish this information

	// package the information into a handle set
	RTI::AttributeHandleSet *attributes = RTI::AttributeHandleSetFactory::create( 3 );
	attributes->add( this->aaHandle );
	attributes->add( this->abHandle );
	attributes->add( this->acHandle );

	// do the actual publication
	rtiamb->publishObjectClass( this->aHandle, *attributes );

	/////////////////////////////////////////////////
	// subscribe to all attributes of ObjectRoot.A //
	/////////////////////////////////////////////////
	// we also want to hear about the same sort of information as it is
	// created and altered in other federates, so we need to subscribe to it
	rtiamb->subscribeObjectClassAttributes( this->aHandle, *attributes );

	/////////////////////////////////////////////////////
	// publish the interaction class InteractionRoot.X //
	/////////////////////////////////////////////////////
	// we want to send interactions of type InteractionRoot.X, so we need
	// to tell the RTI that we're publishing it first. We don't need to
	// inform it of the parameters, only the class, making it much simpler

	// do the publication
	rtiamb->publishInteractionClass( this->xHandle );

	////////////////////////////////////////////////////
	// subscribe to the InteractionRoot.X interaction //
	////////////////////////////////////////////////////
	// we also want to receive other interaction of the same type that are
	// sent out by other federates, so we have to subscribe to it first
	rtiamb->subscribeInteractionClass( this->xHandle );

	// clean up
	delete attributes;
}
void HwFederateAmbassador::provideAttributeValueUpdate (
        RTI::ObjectHandle        theObject,     // supplied C1
  const RTI::AttributeHandleSet& theAttributes) // supplied C4
throw (
  RTI::ObjectNotKnown,
  RTI::AttributeNotKnown,
  RTI::AttributeNotOwned,
  RTI::FederateInternalError)
{
   //-----------------------------------------------------------------
   // Find the Country instance this request is for.
   //-----------------------------------------------------------------
   Country *pCountry = Country::Find( theObject );

   if ( pCountry )
   {
      //-----------------------------------------------------------------
      // Touch the appropriate attribute values in this country
      // instance so that the get updated next cycle.
      //-----------------------------------------------------------------
      RTI::AttributeHandle attrHandle;

      //-----------------------------------------------------------------
      // We need to iterate through the AttributeHandleSet
      // to extract each AttributeHandle.  Based on the type
      // specified ( the value returned by getHandle() ) we need to
      // set the status of whether we should send this type of data.
      //-----------------------------------------------------------------
      for (unsigned int i = 0; i < theAttributes.size(); i++ )
      {
         attrHandle = theAttributes.getHandle( i );
         if ( attrHandle == Country::GetPopulationRtiId() )
         {
            // Touch population so that it gets update next cycle
            pCountry->SetPopulation( pCountry->GetPopulation() );
         }
         else if ( attrHandle == Country::GetNameRtiId() )
         {
            // Touch name so that it gets update next cycle
            pCountry->SetName( pCountry->GetName() );
         }
      }
   }
}
Exemple #5
0
//-----------------------------------------------------------------
//
// METHOD:
//     void Country::PublishAndSubscribe()
//
// PURPOSE:
//     Publishes and Subscribes to Object & Interaction classes
//     and their member data.
//
//     Note: In most reasonable applications this would be broken
//           up into 2 different methods.
//
// RETURN VALUES:
//     None. 
//
// HISTORY:
//     1) Created 11/6/96
//     2) Updated to RTI 1.3 3/26/98
//
//-----------------------------------------------------------------
void Country::PublishAndSubscribe()
{
   if ( ms_rtiAmb )
   {
      //------------------------------------------------------
      // To actually subscribe and publish we need to build
      // an AttributeHandleSet that contains a list of
      // attribute type ids (AttributeHandle).
      //------------------------------------------------------
      RTI::AttributeHandleSet *countryAttributes;
      countryAttributes = RTI::AttributeHandleSetFactory::create(2);

      countryAttributes->add( ms_nameTypeId );
      countryAttributes->add( ms_popTypeId );

      ms_rtiAmb->subscribeObjectClassAttributes( ms_countryTypeId,
                                                *countryAttributes );
      ms_rtiAmb->publishObjectClass( ms_countryTypeId,
                                     *countryAttributes);

      countryAttributes->empty();

      delete countryAttributes;   // Deallocate the memory

      //------------------------------------------------------
      // Same as above for interactions
      //------------------------------------------------------

      // Get RTTI info
      ms_commTypeId    = ms_rtiAmb->getInteractionClassHandle( ms_commTypeStr );

      ms_commMsgTypeId = ms_rtiAmb->getParameterHandle( ms_commMsgTypeStr,
                                                        ms_commTypeId);

      // Declare my Interaction interests
      ms_rtiAmb->subscribeInteractionClass( ms_commTypeId );
      ms_rtiAmb->publishInteractionClass( ms_commTypeId );
   }
}
Exemple #6
0
void CFellow::FellowUpdateControl(RTI::Boolean status,
    const RTI::AttributeHandleSet& theAttrHandles)
{
    RTI::AttributeHandle attrHandle;

    for (unsigned int i = 0; i < theAttrHandles.size(); i++)
    {
        attrHandle = theAttrHandles.getHandle(i);
        if (attrHandle == CFellow::GetFellowNameRtiId())
        {
            m_bNameChanged = status;
        }
        else if (attrHandle == CFellow::GetFellowColorRtiId())
        {
            m_bColorChanged = status;
        }
        else if (attrHandle == CFellow::GetFellowPortraitRtiId())
        {
            m_bPortraitChanged = status;
        }
    }
}