certi-cvs
[Top][All Lists]
Advanced

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

[certi-cvs] applications/HLA_TestsSuite test_TRTCCallbacks....


From: certi-cvs
Subject: [certi-cvs] applications/HLA_TestsSuite test_TRTCCallbacks....
Date: Mon, 05 May 2008 11:35:11 +0000

CVSROOT:        /sources/certi
Module name:    applications
Changes by:     Christian Stenzel <approx>      08/05/05 11:35:11

Added files:
        HLA_TestsSuite : test_TRTCCallbacks.cc test_TRTCCallbacks.fed 

Log message:
        

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/applications/HLA_TestsSuite/test_TRTCCallbacks.cc?cvsroot=certi&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/applications/HLA_TestsSuite/test_TRTCCallbacks.fed?cvsroot=certi&rev=1.1

Patches:
Index: test_TRTCCallbacks.cc
===================================================================
RCS file: test_TRTCCallbacks.cc
diff -N test_TRTCCallbacks.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ test_TRTCCallbacks.cc       5 May 2008 11:35:10 -0000       1.1
@@ -0,0 +1,213 @@
+#include <RTI.hh>
+#include <fedtime.hh>
+#include <NullFederateAmbassador.hh>
+
+#include <iostream>
+#include <sstream>
+#include <memory>
+#include <string>
+
+using std::string;
+using std::cout;
+using std::cerr;
+using std::endl;
+using std::auto_ptr;
+
+#define MAX_FEDERATES 10
+
+class TRTCCallbacksFed : public NullFederateAmbassador {
+
+private:
+    string federationName;
+    string fedFile;
+    bool creator;
+    bool TIMEREGENABLED, TIMECONENABLED;
+
+public:
+    TRTCCallbacksFed(void) {
+        federationName = "TestTRTCCallbacks";
+        fedFile = "test_TRTCCallbacks.fed";
+        creator = false;
+        TIMEREGENABLED = false;
+        TIMECONENABLED = false;
+    };
+
+    virtual ~TRTCCallbacksFed() throw (RTI::FederateInternalError) {
+    };
+
+    int
+    main(void) {
+        this->create_and_join();
+        if (creator) {
+            cout << "Press ENTER to start execution ..." << endl;
+            getchar();
+
+            this->enableTimeReg();
+            while (!TIMEREGENABLED) this->tickRTI();
+           TIMEREGENABLED=false;
+            this->enableTimeCon();
+            while (!TIMECONENABLED) this->tickRTI();
+           TIMECONENABLED=false;
+        } else {
+            this->enableTimeReg();
+            while (!TIMEREGENABLED) this->tickRTI();
+           TIMEREGENABLED=false;
+            this->enableTimeCon();
+            while (!TIMECONENABLED) this->tickRTI();
+           TIMECONENABLED=false;
+        }
+        this->resign_and_destroy();
+        return 0;
+    };
+
+private:
+
+    void
+    create_and_join(void) {
+        try {
+            rtiamb.createFederationExecution(federationName.c_str(),
+                                             fedFile.c_str());
+            creator = true;
+        } catch ( RTI::FederationExecutionAlreadyExists& e) {
+            cout << "--> Federation already created by another federate."
+            << endl;
+        } catch ( RTI::Exception &e ) {
+            cerr << "RTI exception: " << e._name << " ["
+            << (e._reason ? e._reason : "undefined") << "]." << endl;
+        } catch ( ... ) {
+            cerr << "Error: Unknown non-RTI exception." << endl;
+        }
+
+        string federateName = "TRTCCallbacks0";
+        for (int i=1;i<=MAX_FEDERATES;i++) {
+            cout << "Try to join joining federation: " << i << endl;
+            try {
+                cout << "Try to join federation as " << federateName << "." <<
+                endl;
+                rtiamb.joinFederationExecution(federateName.c_str(),
+                                               federationName.c_str(),
+                                               this);
+                cout << "Joined federation as " << federateName << "." <<
+                endl;
+                break;
+            } catch (RTI::FederateAlreadyExecutionMember& e) {
+                cout << "Federate already execution member" << endl;
+                federateName[13] = i+'0';
+                if (i==MAX_FEDERATES) {
+                    cout << "More than " << MAX_FEDERATES << " out there." <<
+                    endl;
+                    exit(-1);
+                }
+                continue;
+            } catch ( RTI::Exception &e ) {
+                cerr << "RTI exception: " << e._name << " ["
+                << (e._reason ? e._reason : "undefined") << "]." << endl;
+            } catch ( ... ) {
+                cerr << "Error: Unknown non-RTI exception." << endl;
+            }
+        }
+
+    }
+
+    void
+    resign_and_destroy(void) {
+        try {
+            rtiamb.resignFederationExecution(
+                RTI::DELETE_OBJECTS_AND_RELEASE_ATTRIBUTES);
+        } catch ( RTI::Exception &e ) {
+            cerr << "RTI exception: " << e._name << " ["
+            << (e._reason ? e._reason : "undefined") << "]." << endl;
+        } catch ( ... ) {
+            cerr << "Error: Unknown non-RTI exception." << endl;
+        }
+
+        try {
+            rtiamb.destroyFederationExecution(federationName.c_str());
+        } catch (RTI::FederatesCurrentlyJoined) {
+            cout << "Federates currently joined." << endl;
+        } catch ( RTI::Exception &e ) {
+            cerr << "RTI exception: " << e._name << " ["
+            << (e._reason ? e._reason : "undefined") << "]." << endl;
+        } catch ( ... ) {
+            cerr << "Error: Unknown non-RTI exception." << endl;
+        }
+    }
+
+    void
+    enableTimeReg(void) {
+        try {
+            rtiamb.enableTimeRegulation(RTIfedTime(0), RTIfedTime(5));
+        } catch ( RTI::Exception &e ) {
+            cerr << "RTI exception: " << e._name << " ["
+            << (e._reason ? e._reason : "undefined") << "]." << endl;
+        } catch ( ... ) {
+            cerr << "Error: unknown non-RTI exception." << endl;
+        }
+    }
+
+    void
+    enableTimeCon(void) {
+        try {
+            rtiamb.enableTimeConstrained();
+            rtiamb.enableAsynchronousDelivery();
+        } catch ( RTI::Exception &e ) {
+            cerr << "RTI exception: " << e._name << " ["
+            << (e._reason ? e._reason : "undefined") << "]." << endl;
+        } catch ( ... ) {
+            cerr << "Error: unknown non-RTI exception." << endl;
+        }
+    }
+
+    void
+    tickRTI(void) {
+        try {
+            rtiamb.tick();
+        } catch ( RTI::Exception &e ) {
+            cerr << "RTI exception: " << e._name << " ["
+            << (e._reason ? e._reason : "undefined") << "]." << endl;
+        } catch ( ... ) {
+            cerr << "Error: unknown non-RTI exception." << endl;
+        }
+    }
+
+    void
+    tickRTI(double min, double max) {
+        try {
+            rtiamb.tick(min, max);
+        } catch ( RTI::Exception &e ) {
+            cerr << "RTI exception: " << e._name << " ["
+            << (e._reason ? e._reason : "undefined") << "]." << endl;
+        } catch ( ... ) {
+            cerr << "Error: unknown non-RTI exception." << endl;
+        }
+    }
+
+    /* Federate Ambassador services */
+    void
+    timeRegulationEnabled(const RTI::FedTime& theTime) 
+    throw (RTI::InvalidFederationTime, 
+          RTI::EnableTimeRegulationWasNotPending, 
+           RTI::FederateInternalError) {
+        cout << "Time Regulation Enabled, press ENTER to continue..." << endl;
+       TIMEREGENABLED = true;
+       getchar();
+    }
+
+    void
+    timeConstrainedEnabled(const RTI::FedTime& theTime) 
+    throw (RTI::InvalidFederationTime, 
+          RTI::EnableTimeConstrainedWasNotPending, 
+           RTI::FederateInternalError) {
+        cout << "Time Constrained Enabled, press ENTER to continue..." << endl;
+       TIMECONENABLED = true;
+       getchar();
+    }
+
+protected:
+    RTI::RTIambassador rtiamb;
+};
+
+int main(int argc, char **argv) {
+    TRTCCallbacksFed testFed;
+    return testFed.main();
+}

Index: test_TRTCCallbacks.fed
===================================================================
RCS file: test_TRTCCallbacks.fed
diff -N test_TRTCCallbacks.fed
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ test_TRTCCallbacks.fed      5 May 2008 11:35:11 -0000       1.1
@@ -0,0 +1,28 @@
+;; TwoLevelController 
+
+(Fed
+  (Federation HugeAVPVTest)
+  (FedVersion v1.3)
+  (Federate "syncFed0" "Public")
+  (Federate "syncFed1" "Public")
+  (Federate "syncFed2" "Public")
+  (Federate "syncFed3" "Public")
+  (Federate "syncFed4" "Public")
+  (Federate "syncFed5" "Public")
+  (Federate "syncFed6" "Public")
+  (Federate "syncFed7" "Public")
+  (Federate "syncFed8" "Public")
+  (Federate "syncFed9" "Public")
+  (Spaces
+  )
+  (Objects
+    (Class ObjectRoot
+      (Attribute privilegeToDelete reliable timestamp)
+      (Class RTIprivate)
+    )
+  )
+  (Interactions
+    (Class InteractionRoot BEST_EFFORT RECEIVE
+    )
+  )
+)




reply via email to

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