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

ShmemRoadDest.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 "RoadDest.h" 00013 #include "RoadStructs.h" 00014 00016 class ShmemRoadDest : public RoadDest { 00017 public: 00018 ShmemRoadDest(); 00019 virtual ~ShmemRoadDest(); 00020 00022 virtual bool outputPoints(utils::Time time, 00023 const std::vector<utils::Vec3d>& points); 00024 00026 bool init(utils::ConfigFile& params, utils::SymbolTable* globals); 00027 00028 private: 00029 IPSharedMemory* _shm; 00030 RoadShmemStruct _output_area; 00031 unsigned int _max_points; 00032 }; 00033 00035 RoadDest* create_RoadDest_shmem(RoadDestGenerator*, 00036 utils::ConfigFile* params, 00037 utils::SymbolTable* globals) 00038 { 00039 ShmemRoadDest* intf = new ShmemRoadDest(); 00040 if (!intf->init(*params, globals)) { 00041 delete intf; 00042 return NULL; 00043 } 00044 return intf; 00045 } 00046 00047 ShmemRoadDest::ShmemRoadDest() 00048 { 00049 _max_points = 5; 00050 _output_area.data.points = new RoadDataPoint[_max_points]; 00051 } 00052 00053 ShmemRoadDest::~ShmemRoadDest() 00054 { 00055 delete [] _output_area.data.points; 00056 } 00057 00058 bool ShmemRoadDest::init(utils::ConfigFile& params, 00059 utils::SymbolTable* globals) 00060 { 00061 // get or create the IPT communicator 00062 // If it is created, it is cached in the global symbol table 00063 IPCommunicator* com = 00064 IPCommunicator::Communicator(globals, 00065 params.getString("ipt_spec", 00066 "unix: int port=0;")); 00067 if (!com) 00068 return false; 00069 00070 // setup the shared memory specification 00071 const char* mem_name = params.getString("name", ROAD_SHMEM_NAME); 00072 char buffer[200]; 00073 // first set up the default, which is based on the memory name 00074 sprintf(buffer, "managed: name=%s; owner=true;", mem_name); 00075 // and then get the spec given the default (i.e., it can be arbitrarily 00076 // overridden 00077 const char* mem_spec = params.getString("mem", buffer); 00078 // get the maximum expected number of points 00079 int max_points = params.getInt("max_points", 20); 00080 // create the shared memory region 00081 _shm = 00082 com->OpenSharedMemory(mem_spec, ROAD_SHMEM_FMT, 00083 sizeof(RoadShmemStruct) + 00084 max_points*sizeof(RoadDataPoint)); 00085 if (!_shm) { 00086 printf("Problem opening shared memory %s\n", mem_spec); 00087 return false; 00088 } 00089 00090 return true; 00091 } 00092 00093 bool ShmemRoadDest::outputPoints(utils::Time time, 00094 const std::vector<utils::Vec3d>& points) 00095 { 00096 // make sure there is enough room in the cached points for the data 00097 if (points.size() > _max_points) { 00098 _max_points = points.size(); 00099 delete [] _output_area.data.points; 00100 _output_area.data.points = new RoadDataPoint[_max_points]; 00101 } 00102 00103 // setup the output area 00104 _output_area.data.num_points = (int) points.size(); 00105 for (int i=0;i<_output_area.data.num_points;i++) { 00106 const utils::Vec3d& src = points[i]; 00107 RoadDataPoint& dest = _output_area.data.points[i]; 00108 dest.x = src.x; 00109 dest.y = src.y; 00110 dest.z = src.z; 00111 } 00112 time.getValue(_output_area.secs, _output_area.usecs); 00113 00114 // and output to shared memory 00115 _shm->PutFormattedData((void*) &_output_area); 00116 00117 return true; 00118 } 00119 00120 00121 00122

Generated on Tue Sep 7 20:37:49 2004 for ModUtils by doxygen 1.3.8