![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /******************************************************************************* 00002 ** Copyright (c) 2010 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *******************************************************************************/ 00005 00008 00009 #pragma once 00010 00011 #include <vrvVrl/DtVrvControlFactory_v0.h> 00012 00013 #include <vlutil/vlPrint.h> 00014 00015 namespace vrvControlToolkit 00016 { 00017 00018 template<class DataMsg> 00019 class DtVrvControlMessageMarshaller_v0 00020 { 00021 public: 00022 DtVrvControlMessageMarshaller_v0(); 00023 00024 virtual ~DtVrvControlMessageMarshaller_v0(); 00025 00026 virtual void encode(DtVrvControl_v0* cmd, DataMsg* msg); 00027 virtual DtVrvControl_v0* decode(const DataMsg* msg); 00028 00029 protected: 00030 00031 }; 00032 00033 00034 00035 template<class DataMsg> 00036 DtVrvControlMessageMarshaller_v0<DataMsg>::DtVrvControlMessageMarshaller_v0() 00037 { 00038 00039 } 00040 00041 template<class DataMsg> 00042 DtVrvControlMessageMarshaller_v0<DataMsg>::~DtVrvControlMessageMarshaller_v0() 00043 { 00044 00045 } 00046 00047 template<class DataMsg> 00048 void DtVrvControlMessageMarshaller_v0<DataMsg>::encode(DtVrvControl_v0* cmd, DataMsg* msg) 00049 { 00050 DtDatumRetCode ret; 00051 int size=cmd->bufferSize(); 00052 00053 //serialize to a buffer 00054 char* buffer=new char[size]; 00055 cmd->encode(buffer); 00056 00057 //setup the var field 00058 msg->setNumVarFields(1); 00059 00060 //odd that these start their indexes at 1 00061 msg->setDatumParam(DtVar, 1, (DtDatumParam)DtVrvDatumParamId_v0); 00062 msg->setVarDataBytes(1, size, &ret); 00063 msg->setDatumValByteArray(DtVar, 1, buffer, &ret); 00064 00065 delete [] buffer; 00066 } 00067 00068 template<class DataMsg> 00069 DtVrvControl_v0* DtVrvControlMessageMarshaller_v0<DataMsg>::decode(const DataMsg* msg) 00070 { 00071 DtDatumRetCode ret; 00072 DtDatumRecordType type; 00073 int index; 00074 int size; 00075 00076 msg->getIndex((DtDatumParam)DtVrvDatumParamId_v0, &type, &index, &ret); 00077 if(ret!=DtDatumValid) 00078 { 00079 return NULL; 00080 } 00081 00082 //actually get the data out of the pdu/interaction 00083 size=msg->datumSizeBytes(type, index); 00084 const char* buffer=msg->datumValByteArray(type, index); 00085 DtVrvControl_v0* cmd=vrvControlToolkit::DtVrvControlFactory_v0::instance().create(buffer, size); 00086 00087 return cmd; 00088 00089 } 00090 00091 } //vrvControlToolkit::