source: pacpusframework/branches/2.0-beta1/src/TestComponents/ShMem/ShMemInput.cpp@ 96

Last change on this file since 96 was 89, checked in by morasjul, 12 years ago

PACPUS 2.0 Beta deployed in new branch

Major changes:
-Add communication interface between components
-Add examples for communications interface (TestComponents)
-Move to Qt5 support

  • Property svn:executable set to *
File size: 2.5 KB
Line 
1#include "ShMemInterface.h"
2
3#include "kernel/ComponentFactory.h"
4#include "kernel/Log.h"
5#include "PacpusTools/ShMem.h"
6#include "Pacpus/kernel/PacpusEvent.h"
7#include "Pacpus/kernel/inputOutputInterface.h"
8
9
10using namespace std;
11using namespace pacpus;
12
13DECLARE_STATIC_LOGGER("pacpus.base.ShMemInput");
14
15// Construct the factory
16static ComponentFactory<ShMemInput> sFactory("ShMemInput");
17
18void ShMemInput::addInputOutput()
19{
20 ADD_INPUT("data",ShMemInput,QByteArray,send);
21}
22
23//////////////////////////////////////////////////////////////////////////
24/// Constructor.
25ShMemInput::ShMemInput(QString name)
26 : ComponentBase(name)
27{
28 LOG_TRACE("constructor(" << name << ")");
29 shMemSize_ = sizeof(size_t);
30 shMemName_ = name; // default name
31 addInputOutput();
32}
33
34//////////////////////////////////////////////////////////////////////////
35/// Destructor.
36ShMemInput::~ShMemInput()
37{
38 LOG_TRACE("destructor");
39
40}
41
42//////////////////////////////////////////////////////////////////////////
43/// Called by the ComponentManager to start the component
44void ShMemInput::startActivity()
45{
46 shmemSize_ = new ShMem(shMemSizeName_.toStdString().c_str(), sizeof(size_t));
47 shmem_ = NULL;
48}
49
50//////////////////////////////////////////////////////////////////////////
51/// Called by the ComponentManager to stop the component
52void ShMemInput::stopActivity()
53{
54 //delete shmemSize_;
55 //delete shmem_;
56}
57
58//////////////////////////////////////////////////////////////////////////
59/// Called by the ComponentManager to pass the XML parameters to the
60/// component
61ComponentBase::COMPONENT_CONFIGURATION ShMemInput::configureComponent(XmlComponentConfig config)
62{
63 if (param.getProperty("memoryName") != QString::null)
64 shMemName_ = param.getProperty("memoryName");
65// if (param.getProperty("alascaPort") != QString::null)
66// port_ = param.getProperty("alascaPort").toInt();
67
68 shMemSizeName_ = shMemName_ + "Size";
69
70 return ComponentBase::CONFIGURED_OK;
71}
72
73void ShMemInput::send(const QByteArray& data)
74{
75 qDebug() << "t[10]= " << road_time();
76 if(shmem_ == NULL) {
77 shMemSize_ = data.size();
78 shmem_ = new ShMem(shMemName_.toStdString().c_str(), shMemSize_);
79 LOG_WARN("Shared Memory allocated");
80 }
81
82 if(data.size() != shMemSize_) {
83 LOG_WARN("Shared Memory size incorect");
84 return;
85 }
86 qDebug() << "t[11]= " << road_time();
87 shmemSize_->write(&shMemSize_,sizeof(size_t));
88 shmem_->write((void*)(data.data()),shMemSize_); // copy 4
89
90
91 qDebug() << "t[12]= " << road_time();
92
93}
Note: See TracBrowser for help on using the repository browser.