示例#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;
    }
}
示例#2
0
/*
 * 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;
}
示例#3
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 );
   }
}