Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

ShmemVehPoseDest.cc

Go to the documentation of this file.
00001 
00005 #include <stdio.h>
00006 #include <ipt/ipt.h>
00007 #include <ipt/sharedmem.h>
00008 
00009 #include <utils/SymbolTable.h>
00010 #include <utils/ConfigFile.h>
00011 
00012 #include "VehPoseDest.h"
00013 #include "VehPoseStructs.h"
00014 
00016 class ShmemVehPoseDest : public VehPoseDest {
00017  public:
00019   virtual bool outputPose(utils::Time time, const VehPose& veh_pose);
00020 
00022   bool init(utils::ConfigFile& params, utils::SymbolTable* globals);
00023 
00024  private:
00025   IPSharedMemory* _shm;  
00026   VehPoseShmemStruct _output_area;  
00027 };
00028 
00030 UTILS_INTF_CREATOR(VehPoseDest, shmem, gen, params, globals)
00031 {
00032   UTILS_INTF_REPORT(VehPoseDest, shmem);
00033   ShmemVehPoseDest* intf = new ShmemVehPoseDest();
00034   if (!intf->init(*params, globals)) {
00035     delete intf;
00036     return NULL;
00037   }
00038   return intf;
00039 }
00040 
00041 bool ShmemVehPoseDest::init(utils::ConfigFile& params,
00042                          utils::SymbolTable* globals)
00043 {
00044   // get or create the IPT communicator
00045   // If it is created, it is cached in the global symbol table
00046   IPCommunicator* com =
00047     IPCommunicator::Communicator(globals, 
00048                                  params.getString("ipt_spec",
00049                                                   "unix: int port=0;"));
00050   if (!com)
00051     return false;
00052 
00053   // setup the shared memory specification
00054   const char* mem_name = params.getString("name", VEH_POSE_SHMEM_NAME);
00055   char buffer[200];
00056   // first set up the default, which is based on the memory name
00057   sprintf(buffer, "managed: name=%s; owner=true;", mem_name);
00058   // and then get the spec given the default (i.e., it can be arbitrarily
00059   // overridden
00060   const char* mem_spec = params.getString("mem", buffer);
00061   // create the shared memory region
00062   _shm =
00063     com->OpenSharedMemory(mem_spec, VEH_POSE_SHMEM_FMT,
00064                           sizeof(VehPoseShmemStruct));
00065   if (!_shm) {
00066     printf("Problem opening shared memory %s\n", mem_spec);
00067     return false;
00068   }
00069 
00070   return true;
00071 }
00072 
00073 bool ShmemVehPoseDest::outputPose(utils::Time time, const VehPose& veh_pose)
00074 {
00075   // setup the output area
00076   _output_area.data.x = veh_pose.pos.x;
00077   _output_area.data.y = veh_pose.pos.y;
00078   _output_area.data.z = veh_pose.pos.z;
00079   _output_area.data.ori[0] = veh_pose.ori[0];
00080   _output_area.data.ori[1] = veh_pose.ori[1];
00081   _output_area.data.ori[2] = veh_pose.ori[2];
00082   _output_area.data.ori[3] = veh_pose.ori[3];
00083   time.getValue(_output_area.secs, _output_area.usecs);
00084 
00085   // and output to shared memory
00086   _shm->PutFormattedData((void*) &_output_area);
00087 
00088   return true;
00089 }
00090 
00091 
00092 
00093   

Generated on Fri Jun 16 13:21:19 2006 for ModUtils by  doxygen 1.4.4