Yuki Suga / RTnoV4

Dependencies:   EthernetInterface mbed-rtos

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers InPort.h Source File

InPort.h

00001 #ifndef INPORT_HEADER_INCLUDED
00002 #define INPORT_HEADER_INCLUDED
00003 
00004 /*******************************************
00005  * InPort.h
00006  * @author Yuki Suga
00007  * @copyright Yuki Suga (ysuga.net) Nov, 10th, 2010.
00008  * @license LGPLv3
00009  *****************************************/
00010 
00011 #include <stdint.h>
00012 #include "PortBase.h"
00013 #include "NullBuffer.h"
00014 #include <string.h>
00015 #include <stdlib.h>
00016 
00017 class InPortBase : public PortBase{
00018  private:
00019 
00020  public:
00021   InPortBase(char* name, char tCode) {
00022     PortBase_init(this, name, tCode, NullBuffer_create());
00023   }
00024 
00025  public:
00026 
00027 };
00028 
00029 template<typename T>
00030 class InPort : public InPortBase {
00031  public:
00032   T* m_pData;
00033  public:
00034  InPort(char* name, T& data) : InPortBase(name, data.typeCode) {
00035     m_pData = &data;
00036   }
00037 
00038   ~InPort() {}
00039  public:
00040   uint8_t isNew() {
00041     return pPortBuffer->hasNext(pPortBuffer);
00042   }
00043 
00044   uint8_t read() {
00045     uint8_t dataSize = pPortBuffer->getNextDataSize(pPortBuffer);
00046     if(TypeCode_isSequence(m_pData->typeCode)) {
00047       ((SequenceBase*)&(m_pData->data))->length(dataSize/TypeCode_getElementSize(m_pData->typeCode));
00048       pPortBuffer->pop(pPortBuffer, (int8_t*)((SequenceBase*)&(m_pData->data))->getData(), dataSize);
00049     } else {
00050     // This code must be okay for little endian system.
00051       pPortBuffer->pop(pPortBuffer, (int8_t*)&(m_pData->data), dataSize);
00052     }
00053     return dataSize;
00054   }
00055 
00056 };
00057 
00058 
00059 
00060 #endif