certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] applications/HLA_TestsSuite test_Inheritance.cc


From: CERTI CVS commits
Subject: [certi-cvs] applications/HLA_TestsSuite test_Inheritance.cc
Date: Sat, 31 Dec 2011 15:50:21 +0000

CVSROOT:        /sources/certi
Module name:    applications
Changes by:     Eric NOULARD <erk>      11/12/31 15:50:21

Modified files:
        HLA_TestsSuite : test_Inheritance.cc 

Log message:
        Continue development of inheritance test.
        Already usable for interactions

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/applications/HLA_TestsSuite/test_Inheritance.cc?cvsroot=certi&r1=1.1&r2=1.2

Patches:
Index: test_Inheritance.cc
===================================================================
RCS file: /sources/certi/applications/HLA_TestsSuite/test_Inheritance.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- test_Inheritance.cc 30 Dec 2011 16:51:55 -0000      1.1
+++ test_Inheritance.cc 31 Dec 2011 15:50:21 -0000      1.2
@@ -38,6 +38,14 @@
     RTI::ParameterHandle          parameterId;
     bool                          verbose;
 
+    void showRTIException(RTI::Exception& e, std::ostream& os, bool withEndl) {
+        os << "RTI::Exception<" << e._name <<"> ["
+             << (e._reason ? e._reason : "undefined") << "]";
+        if (withEndl) {
+            os << std::endl;
+        }
+    }
+
 public:
     InheritanceFederate(std::string federationFile, std::string 
federationName, bool verbose=false) {
         this->verbose        = verbose;
@@ -47,6 +55,10 @@
         }
         this->federationFile = federationFile;
         this->federationName = federationName;
+        this->objectClassId      = 0;
+        this->attributeId        = 0;
+        this->interactionClassId = 0;
+        this->parameterId        = 0;
     };
 
     virtual ~InheritanceFederate() throw (RTI::FederateInternalError) {
@@ -64,7 +76,7 @@
             }
             retval = true;
         } catch ( RTI::FederationExecutionAlreadyExists& e) {
-            cout << "--> Federation already created by another federate." << 
endl;
+            cout << "--> Federation already created [probably] by another 
federate." << endl;
         } catch ( RTI::Exception &e ) {
             cerr << "RTI exception: " << e._name << " ["
                     << (e._reason ? e._reason : "undefined") << "]." << endl;
@@ -195,26 +207,75 @@
     bool
     publish() {
         bool retval = false;
+        if (interactionClassId>0) {
+            try {
+                myRTIamb.publishInteractionClass(interactionClassId);
+                retval = true;
+            } catch (RTI::Exception& e) {
+                cerr << "Unable to publishInteractionClass:";
+                showRTIException(e,cerr,true);
+            }
+        }
+        if ((objectClassId>0) & (attributeId>0)) {
+            try {
+                auto_ptr<RTI::AttributeHandleSet> 
attributes(RTI::AttributeHandleSetFactory::create(1));
+                attributes->add(attributeId);
+                myRTIamb.publishObjectClass(objectClassId,*attributes);
+                retval = true;
+            } catch (RTI::Exception& e) {
+                cerr << "Unable to publishObjectClass:";
+                showRTIException(e,cerr,true);
+                retval = false;
+            }
+        }
         return retval;
     } /* end of publish */
 
     bool
     unpublish() {
         bool retval = false;
+        if (interactionClassId>0) {
+            try {
+                myRTIamb.unpublishInteractionClass(interactionClassId);
+                retval = true;
+            } catch (RTI::Exception& e) {
+                cerr << "Unable to unpublishInteractionClass" << endl;
+            }
+        }
+        if ((objectClassId>0) & (attributeId>0)) {
+            try {
+                myRTIamb.unpublishObjectClass(objectClassId);
+                retval = true;
+            } catch (RTI::Exception& e) {
+                cerr << "Unable to unpublishObjectClass" << endl;
+                retval = false;
+            }
+        }
         return retval;
     } /* end of unpublish */
 
     void UAV() {
 
-    }
+    } /* end of UAV */
 
     void SI() {
-
+        auto_ptr<RTI::ParameterHandleValuePairSet> 
parameters(RTI::ParameterSetFactory::create(1));
+        /* parameters->add(parameterId,; */
+        try {
+            myRTIamb.sendInteraction(interactionClassId,*parameters,"");
+            if (verbose) {
+                cout << "SI<" << interactionClassId << ">" << endl;
     }
+        } catch (RTI::Exception& e) {
+            cerr << "Unable to sendInteraction:";
+            showRTIException(e,cerr,true);
+        }
+    } /* end of SI */
 
     bool
     subscribe() {
         bool retval = false;
+        if (objectClassId>0) {
         // Add attribute handle to the attribute set
         // Before, we create the Set with one attribute
         auto_ptr<RTI::AttributeHandleSet> 
attributes(RTI::AttributeHandleSetFactory::create(1));
@@ -223,28 +284,45 @@
             myRTIamb.subscribeObjectClassAttributes(objectClassId,*attributes);
             retval = true;
         } catch (RTI::Exception& e) {
-            cerr << "Unable to subscribe" << endl;
+                cerr << "Unable to subscribeObjectClassAttributes:";
+                showRTIException(e,cerr,true);
+            }
+        }
+        if (interactionClassId>0) {
+            try {
+                myRTIamb.subscribeInteractionClass(interactionClassId);
+                retval = true;
+            } catch (RTI::Exception& e) {
+                cerr << "Unable to subscribeInteractionClass:";
+                showRTIException(e,cerr,true);
+                retval = false;
+            }
         }
         return retval;
     } /* end of subscribe */
 
     bool
-    unsubscribe(std::string className) {
+    unsubscribe() {
         bool retval = true;
-        RTI::ObjectClassHandle classId;
-
+        if (objectClassId>0) {
         try {
-            classId = myRTIamb.getObjectClassHandle(className.c_str());
+                myRTIamb.unsubscribeObjectClass(objectClassId);
         } catch (RTI::Exception& e) {
-            cerr << "Unable to obtain class handle for class <"<< 
className<<">" <<endl;
+                cerr << "Unable to unsubscribeObjectClass:";
+                showRTIException(e,cerr,true);
             retval = false;
         }
+        }
+        if (interactionClassId>0) {
         try {
-            myRTIamb.unsubscribeObjectClass(classId);
+                myRTIamb.unsubscribeInteractionClass(interactionClassId);
+                retval = true;
         } catch (RTI::Exception& e) {
-            cerr << "Unable to unsubscribe" << endl;
+                cerr << "Unable to unsubscribeInteractionClass:";
+                showRTIException(e,cerr,true);
             retval = false;
         }
+        }
         return retval;
     } /* end of unsubscribe */
 
@@ -252,9 +330,11 @@
     tickRTI() {
         try {
             myRTIamb.tick();
-        } catch ( RTI::Exception &e ) {
-            cerr << "RTI exception: " << e._name << " ["
-                    << (e._reason ? e._reason : "undefined") << "]." << endl;
+            if (verbose) {
+                cout << "tick()."<<endl;
+            }
+        } catch (RTI::Exception& e) {
+            showRTIException(e,cerr,true);
         } catch ( ... ) {
             cerr << "Error: unknown non-RTI exception." << endl;
         }
@@ -264,9 +344,11 @@
     tickRTI(double min, double max) {
         try {
             myRTIamb.tick(min, max);
-        } catch ( RTI::Exception &e ) {
-            cerr << "RTI exception: " << e._name << " ["
-                    << (e._reason ? e._reason : "undefined") << "]." << endl;
+            if (verbose) {
+                cout << "tick("<< min <<","<<max<<")."<<endl;
+            }
+         } catch (RTI::Exception &e) {
+            showRTIException(e,cerr,true);
         } catch ( ... ) {
             cerr << "Error: unknown non-RTI exception." << endl;
         }
@@ -348,6 +430,16 @@
         }
     }
 
+    /* subscribe or publish */
+    if (!args.subscribe_flag) {
+        cout << args.fedname_arg << " is a PUBLISHER" << endl;
+        InheritanceFederate.publish();
+    } else {
+        cout << args.fedname_arg << " is a SUBSCRIBER" << endl;
+        InheritanceFederate.subscribe();
+    }
+
+    /* main simulation loop */
     for (int i=0; i< args.time_arg; ++i) {
         if (!args.subscribe_flag) {
            InheritanceFederate.UAV();
@@ -356,6 +448,13 @@
         InheritanceFederate.tickRTI(1,2);
     }
 
+    /* un-subscribe or un-publish */
+    if (!args.subscribe_flag) {
+        InheritanceFederate.unpublish();
+    } else {
+        InheritanceFederate.unsubscribe();
+    }
+
     if (args.joinname_given) {
         status &= InheritanceFederate.resign();
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]