certi-cvs
[Top][All Lists]
Advanced

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

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


From: certi-cvs
Subject: [certi-cvs] applications/HLA_TestsSuite test_FOMParse_cmdli...
Date: Tue, 21 Oct 2008 10:30:36 +0000

CVSROOT:        /sources/certi
Module name:    applications
Changes by:     Eric NOULARD <erk>      08/10/21 10:30:36

Modified files:
        HLA_TestsSuite : test_FOMParse_cmdline.c test_FOMParse_cmdline.h 
                         test_FOMParse.ggo test_FOMParse.cc 

Log message:
        Update
        One may now subscribe to an object class and attribute

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/applications/HLA_TestsSuite/test_FOMParse_cmdline.c?cvsroot=certi&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/applications/HLA_TestsSuite/test_FOMParse_cmdline.h?cvsroot=certi&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/applications/HLA_TestsSuite/test_FOMParse.ggo?cvsroot=certi&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/applications/HLA_TestsSuite/test_FOMParse.cc?cvsroot=certi&r1=1.2&r2=1.3

Patches:
Index: test_FOMParse_cmdline.c
===================================================================
RCS file: /sources/certi/applications/HLA_TestsSuite/test_FOMParse_cmdline.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- test_FOMParse_cmdline.c     20 Oct 2008 21:06:06 -0000      1.1
+++ test_FOMParse_cmdline.c     21 Oct 2008 10:30:29 -0000      1.2
@@ -24,20 +24,23 @@
 
 const char *gengetopt_args_info_usage = "Usage: test_FOMParse -f <fedfile> -n 
<FederationName> [-v]";
 
-const char *gengetopt_args_info_description = "Use by the CERTI HLA TestSuite";
+const char *gengetopt_args_info_description = "A FOM parse test which is part 
of the CERTI HLA TestsSuite";
 
 const char *gengetopt_args_info_help[] = {
   "  -h, --help            Print help and exit",
   "  -V, --version         Print version and exit",
   "  -f, --fedfile=STRING  The FED file (XML or FED) to be used",
   "  -n, --fedname=STRING  The Federation name",
-  "  -v, --verbose=SHORT   verbose mode",
+  "  -j, --joinname=STRING   The federate name used to join the federation",
+  "  -c, --classname=STRING  The object class to subscribe to (or publish)",
+  "  -a, --attname=STRING    The attribute name to subscribe to (or publish)",
+  "  -v, --verbose           verbose mode  (default=off)",
     0
 };
 
 typedef enum {ARG_NO
+  , ARG_FLAG
   , ARG_STRING
-  , ARG_SHORT
 } cmdline_parser_arg_type;
 
 static
@@ -62,6 +65,9 @@
   args_info->version_given = 0 ;
   args_info->fedfile_given = 0 ;
   args_info->fedname_given = 0 ;
+  args_info->joinname_given = 0 ;
+  args_info->classname_given = 0 ;
+  args_info->attname_given = 0 ;
   args_info->verbose_given = 0 ;
 }
 
@@ -72,7 +78,13 @@
   args_info->fedfile_orig = NULL;
   args_info->fedname_arg = NULL;
   args_info->fedname_orig = NULL;
-  args_info->verbose_orig = NULL;
+  args_info->joinname_arg = NULL;
+  args_info->joinname_orig = NULL;
+  args_info->classname_arg = NULL;
+  args_info->classname_orig = NULL;
+  args_info->attname_arg = NULL;
+  args_info->attname_orig = NULL;
+  args_info->verbose_flag = 0;
   
 }
 
@@ -85,7 +97,10 @@
   args_info->version_help = gengetopt_args_info_help[1] ;
   args_info->fedfile_help = gengetopt_args_info_help[2] ;
   args_info->fedname_help = gengetopt_args_info_help[3] ;
-  args_info->verbose_help = gengetopt_args_info_help[4] ;
+  args_info->joinname_help = gengetopt_args_info_help[4] ;
+  args_info->classname_help = gengetopt_args_info_help[5] ;
+  args_info->attname_help = gengetopt_args_info_help[6] ;
+  args_info->verbose_help = gengetopt_args_info_help[7] ;
   
 }
 
@@ -168,7 +183,12 @@
   free_string_field (&(args_info->fedfile_orig));
   free_string_field (&(args_info->fedname_arg));
   free_string_field (&(args_info->fedname_orig));
-  free_string_field (&(args_info->verbose_orig));
+  free_string_field (&(args_info->joinname_arg));
+  free_string_field (&(args_info->joinname_orig));
+  free_string_field (&(args_info->classname_arg));
+  free_string_field (&(args_info->classname_orig));
+  free_string_field (&(args_info->attname_arg));
+  free_string_field (&(args_info->attname_orig));
   
   
 
@@ -206,8 +226,14 @@
     write_into_file(outfile, "fedfile", args_info->fedfile_orig, 0);
   if (args_info->fedname_given)
     write_into_file(outfile, "fedname", args_info->fedname_orig, 0);
+  if (args_info->joinname_given)
+    write_into_file(outfile, "joinname", args_info->joinname_orig, 0);
+  if (args_info->classname_given)
+    write_into_file(outfile, "classname", args_info->classname_orig, 0);
+  if (args_info->attname_given)
+    write_into_file(outfile, "attname", args_info->attname_orig, 0);
   if (args_info->verbose_given)
-    write_into_file(outfile, "verbose", args_info->verbose_orig, 0);
+    write_into_file(outfile, "verbose", 0, 0 );
   
 
   i = EXIT_SUCCESS;
@@ -1027,8 +1053,8 @@
     val = possible_values[found];
 
   switch(arg_type) {
-  case ARG_SHORT:
-    if (val) *((short *)field) = (short)strtol (val, &stop_char, 0);
+  case ARG_FLAG:
+    *((int *)field) = !*((int *)field);
     break;
   case ARG_STRING:
     if (val) {
@@ -1042,21 +1068,11 @@
     break;
   };
 
-  /* check numeric conversion */
-  switch(arg_type) {
-  case ARG_SHORT:
-    if (val && !(stop_char && *stop_char == '\0')) {
-      fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
-      return 1; /* failure */
-    }
-    break;
-  default:
-    ;
-  };
 
   /* store the original value */
   switch(arg_type) {
   case ARG_NO:
+  case ARG_FLAG:
     break;
   default:
     if (value && orig_field) {
@@ -1114,7 +1130,10 @@
         { "version",   0, NULL, 'V' },
         { "fedfile",   1, NULL, 'f' },
         { "fedname",   1, NULL, 'n' },
-        { "verbose",   1, NULL, 'v' },
+        { "joinname",  1, NULL, 'j' },
+        { "classname", 1, NULL, 'c' },
+        { "attname",   1, NULL, 'a' },
+        { "verbose",   0, NULL, 'v' },
         { NULL,        0, NULL, 0 }
       };
 
@@ -1123,7 +1142,7 @@
       custom_opterr = opterr;
       custom_optopt = optopt;
 
-      c = custom_getopt_long (argc, argv, "hVf:n:v:", long_options, 
&option_index);
+      c = custom_getopt_long (argc, argv, "hVf:n:j:c:a:v", long_options, 
&option_index);
 
       optarg = custom_optarg;
       optind = custom_optind;
@@ -1168,14 +1187,48 @@
             goto failure;
         
           break;
-        case 'v':      /* verbose mode.  */
+        case 'j':      /* The federate name used to join the federation.  */
+        
+        
+          if (update_arg( (void *)&(args_info->joinname_arg), 
+               &(args_info->joinname_orig), &(args_info->joinname_given),
+              &(local_args_info.joinname_given), optarg, 0, 0, ARG_STRING,
+              check_ambiguity, override, 0, 0,
+              "joinname", 'j',
+              additional_error))
+            goto failure;
+        
+          break;
+        case 'c':      /* The object class to subscribe to (or publish).  */
         
         
-          if (update_arg( (void *)&(args_info->verbose_arg), 
-               &(args_info->verbose_orig), &(args_info->verbose_given),
-              &(local_args_info.verbose_given), optarg, 0, 0, ARG_SHORT,
+          if (update_arg( (void *)&(args_info->classname_arg), 
+               &(args_info->classname_orig), &(args_info->classname_given),
+              &(local_args_info.classname_given), optarg, 0, 0, ARG_STRING,
               check_ambiguity, override, 0, 0,
-              "verbose", 'v',
+              "classname", 'c',
+              additional_error))
+            goto failure;
+        
+          break;
+        case 'a':      /* The attribute name to subscribe to (or publish).  */
+        
+        
+          if (update_arg( (void *)&(args_info->attname_arg), 
+               &(args_info->attname_orig), &(args_info->attname_given),
+              &(local_args_info.attname_given), optarg, 0, 0, ARG_STRING,
+              check_ambiguity, override, 0, 0,
+              "attname", 'a',
+              additional_error))
+            goto failure;
+        
+          break;
+        case 'v':      /* verbose mode.  */
+        
+        
+          if (update_arg((void *)&(args_info->verbose_flag), 0, 
&(args_info->verbose_given),
+              &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG,
+              check_ambiguity, override, 1, 0, "verbose", 'v',
               additional_error))
             goto failure;
         

Index: test_FOMParse_cmdline.h
===================================================================
RCS file: /sources/certi/applications/HLA_TestsSuite/test_FOMParse_cmdline.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- test_FOMParse_cmdline.h     20 Oct 2008 21:06:06 -0000      1.1
+++ test_FOMParse_cmdline.h     21 Oct 2008 10:30:32 -0000      1.2
@@ -26,7 +26,7 @@
 
 #ifndef CMDLINE_PARSER_VERSION
 /** @brief the program version */
-#define CMDLINE_PARSER_VERSION "1.1"
+#define CMDLINE_PARSER_VERSION "0.1"
 #endif
 
 /** @brief Where the command line options are stored */
@@ -40,14 +40,25 @@
   char * fedname_arg;  /**< @brief The Federation name.  */
   char * fedname_orig; /**< @brief The Federation name original value given at 
command line.  */
   const char *fedname_help; /**< @brief The Federation name help description.  
*/
-  short verbose_arg;   /**< @brief verbose mode.  */
-  char * verbose_orig; /**< @brief verbose mode original value given at 
command line.  */
+  char * joinname_arg; /**< @brief The federate name used to join the 
federation.  */
+  char * joinname_orig;        /**< @brief The federate name used to join the 
federation original value given at command line.  */
+  const char *joinname_help; /**< @brief The federate name used to join the 
federation help description.  */
+  char * classname_arg;        /**< @brief The object class to subscribe to 
(or publish).  */
+  char * classname_orig;       /**< @brief The object class to subscribe to 
(or publish) original value given at command line.  */
+  const char *classname_help; /**< @brief The object class to subscribe to (or 
publish) help description.  */
+  char * attname_arg;  /**< @brief The attribute name to subscribe to (or 
publish).  */
+  char * attname_orig; /**< @brief The attribute name to subscribe to (or 
publish) original value given at command line.  */
+  const char *attname_help; /**< @brief The attribute name to subscribe to (or 
publish) help description.  */
+  int verbose_flag;    /**< @brief verbose mode (default=off).  */
   const char *verbose_help; /**< @brief verbose mode help description.  */
   
   unsigned int help_given ;    /**< @brief Whether help was given.  */
   unsigned int version_given ; /**< @brief Whether version was given.  */
   unsigned int fedfile_given ; /**< @brief Whether fedfile was given.  */
   unsigned int fedname_given ; /**< @brief Whether fedname was given.  */
+  unsigned int joinname_given ;        /**< @brief Whether joinname was given. 
 */
+  unsigned int classname_given ;       /**< @brief Whether classname was 
given.  */
+  unsigned int attname_given ; /**< @brief Whether attname was given.  */
   unsigned int verbose_given ; /**< @brief Whether verbose was given.  */
 
 } ;

Index: test_FOMParse.ggo
===================================================================
RCS file: /sources/certi/applications/HLA_TestsSuite/test_FOMParse.ggo,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- test_FOMParse.ggo   20 Oct 2008 21:06:06 -0000      1.1
+++ test_FOMParse.ggo   21 Oct 2008 10:30:34 -0000      1.2
@@ -1,10 +1,10 @@
 # This is used by gengetopt to generate test_FOMParse command line parser
 # see http://www.gnu.org/software/gengetopt/gengetopt.html#Basic-Usage
 package                "FOMParse"
-version                "1.1"
+version                "0.1"
 purpose                "test FOM parsing"
 usage          "test_FOMParse -f <fedfile> -n <FederationName> [-v]"
-description    "Use by the CERTI HLA TestSuite"
+description    "A FOM parse test which is part of the CERTI HLA TestsSuite"
 
 # gengetopt options
 args "-F test_FOMParse_cmdline -G"
@@ -12,4 +12,7 @@
 # Options
 option "fedfile"       f "The FED file (XML or FED) to be used"        string  
   required
 option "fedname"    n "The Federation name" string required
-option "verbose"       v "verbose mode"                        short   optional
+option "joinname"   j "The federate name used to join the federation" string  
optional
+option "classname"  c "The object class to subscribe to (or publish)" string 
optional
+option "attname"    a "The attribute name to subscribe to (or publish)" string 
optional
+option "verbose"       v "verbose mode"                        flag   off

Index: test_FOMParse.cc
===================================================================
RCS file: /sources/certi/applications/HLA_TestsSuite/test_FOMParse.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- test_FOMParse.cc    20 Oct 2008 21:21:42 -0000      1.2
+++ test_FOMParse.cc    21 Oct 2008 10:30:34 -0000      1.3
@@ -11,10 +11,10 @@
 #include <stdlib.h>
 
 #if defined(_WIN32)
-    #include <windows.h>
-    #include <algorithm>
-    #include <process.h>
-    #define    sleep(a)              Sleep(a * 1000)
+#include <windows.h>
+#include <algorithm>
+#include <process.h>
+#define        sleep(a)              Sleep(a * 1000)
 #endif
 
 using std::string;
@@ -22,7 +22,10 @@
 using std::cerr;
 using std::endl;
 using std::auto_ptr;
-
+/**
+ * The ParseFederate inherit from the classical
+ * NullFederateAmbassador.
+ */
 class ParseFederate : public NullFederateAmbassador {
 
 private:
@@ -44,15 +47,6 @@
     virtual ~ParseFederate() throw (RTI::FederateInternalError) {
     };
 
-    int
-    main(void) {
-        this->create();
-        this->destroy();
-        return 0;
-    };
-
-private:
-
     void
     create() {
         try {
@@ -69,7 +63,7 @@
     } /* end of create */
 
     void
-    destroy(void) {
+       destroy() {
         try {
             myRTIamb.destroyFederationExecution(federationName.c_str());
         } catch (RTI::FederatesCurrentlyJoined) {
@@ -82,8 +76,96 @@
         }
     } /* end of destroy */
 
+       void join(std::string federateName) {
+               try {
+                       if (verbose) {
+                               cout << "Try to join federation as <" << 
federateName << ">...";
+                       }
+                       myRTIamb.joinFederationExecution(federateName.c_str(),
+                                       federationName.c_str(),
+                                       this);
+                       if (verbose) {
+                               cout << "Done." << endl;
+                       }
+               } catch (RTI::FederateAlreadyExecutionMember& e) {
+                       cerr << "Federate already execution member" << endl;
+               } catch ( RTI::Exception &e ) {
+                       cerr << "RTI exception: " << e._name << " ["
+                       << (e._reason ? e._reason : "undefined") << "]." << 
endl;
+               } catch ( ... ) {
+                       cerr << "Error: Unknown non-RTI exception." << endl;
+               }
+       } /* end of join */
+
+       void resign() {
+
+               try {
+                       if (verbose) {
+                               cout << "Try to resign from federation...";
+                       }
+                       
myRTIamb.resignFederationExecution(RTI::DELETE_OBJECTS_AND_RELEASE_ATTRIBUTES);
+                       if (verbose) {
+                               cout << "Done." << endl;
+                       }
+               } catch ( RTI::Exception &e ) {
+                       cerr << "RTI exception: " << e._name << " ["
+                       << (e._reason ? e._reason : "undefined") << "]." << 
endl;
+               } catch ( ... ) {
+                       cerr << "Error: Unknown non-RTI exception." << endl;
+               }
+       } /* end of resign */
+
+       void publish() {
+
+       } /* end of publish */
+
+       void subscribe(std::string className, std::string attributeName) {
+               RTI::ObjectClassHandle classId;
+               RTI::AttributeHandle   attId;
+               if (verbose) {
+                       cout << "Getting handles..." <<endl;
+               }
+               try {
+                       classId = 
myRTIamb.getObjectClassHandle(className.c_str());
+                       cout << "   " << className << " ID = " << classId << 
endl;
+               } catch (RTI::Exception& e) {
+                       cerr << "   Unable to obtain class handle for class 
<"<< className<<">" <<endl;
+               }
+               try {
+                       attId = 
myRTIamb.getAttributeHandle(attributeName.c_str(),classId);
+                       cout << "   " << attributeName << " ID = " << attId << 
endl;
+               } catch (RTI::Exception& e){
+                       cerr << "   Unable to obtain attribute handle for 
attribute <"<< attributeName<<">" <<endl;
+               }
+
+               // Add attribute handle to the attribute set
+               // Before, we create the Set with one attribute
+               auto_ptr<RTI::AttributeHandleSet> 
attributes(RTI::AttributeHandleSetFactory::create(1));
+               attributes->add(attId);
+               try {
+                       
myRTIamb.subscribeObjectClassAttributes(classId,*attributes);
+               } catch (RTI::Exception& e) {
+                       cerr << "Unable to subscribe" << endl;
+               }
+       } /* end of subscribe */
+
+       void unsubscribe(std::string className) {
+               RTI::ObjectClassHandle classId;
+
+               try {
+                       classId = 
myRTIamb.getObjectClassHandle(className.c_str());
+               } catch (RTI::Exception& e) {
+                       cerr << "Unable to obtain class handle for class <"<< 
className<<">" <<endl;
+               }
+               try {
+                       myRTIamb.unsubscribeObjectClass(classId);
+               } catch (RTI::Exception& e) {
+                       cerr << "Unable to unsubscribe" << endl;
+               }
+       } /* end of unsubscribe */
+
     void
-    tickRTI(void) {
+       tickRTI() {
         try {
             myRTIamb.tick();
         } catch ( RTI::Exception &e ) {
@@ -92,7 +174,7 @@
         } catch ( ... ) {
             cerr << "Error: unknown non-RTI exception." << endl;
         }
-    }
+       } /* end of tickRTI() */
 
     void
     tickRTI(double min, double max) {
@@ -104,20 +186,45 @@
         } catch ( ... ) {
             cerr << "Error: unknown non-RTI exception." << endl;
         }
-    }
+       } /* end of tickRTI(double,double) */
 
 protected:
+
+
     RTI::RTIambassador myRTIamb;
 };
 
 int main(int argc, char **argv) {
 
-       // Command line
+       // Command line arguments handling (generated with gengetopt)
        gengetopt_args_info args ;
        if (cmdline_parser(argc, argv, &args))
                    exit(EXIT_FAILURE);
 
     ParseFederate parseFederate(std::string(args.fedfile_arg),
-                                                               
std::string(args.fedname_arg),args.verbose_arg);
-    return parseFederate.main();
+                       std::string(args.fedname_arg),args.verbose_flag);
+
+       parseFederate.create();
+       if (args.joinname_given) {
+               parseFederate.join(std::string(args.joinname_arg));
+       }
+
+       if (args.classname_given && args.attname_given) {
+               parseFederate.subscribe(std::string(args.classname_arg),
+                               std::string(args.attname_arg));
+       }
+
+       parseFederate.tickRTI(1,2);
+
+       if (args.classname_given && args.attname_given) {
+               parseFederate.unsubscribe(std::string(args.classname_arg));
+       }
+
+       if (args.joinname_given) {
+               parseFederate.resign();
+       }
+
+       parseFederate.destroy();
+
+       return 0;
 }




reply via email to

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