source: flair-src/trunk/lib/FlairCore/src/SendData.cpp@ 26

Last change on this file since 26 was 15, checked in by Bayard Gildas, 9 years ago

sources reformatted with flair-format-dir script

File size: 3.1 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5// created: 2012/03/07
6// filename: SendData.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Abstract class for sending datas to ground station
14//
15//
16/*********************************************************************/
17
18#include "SendData.h"
19#include "SendData_impl.h"
20#include "Layout.h"
21#include "LayoutPosition.h"
22#include "FrameworkManager.h"
23#include "FrameworkManager_impl.h"
24
25using namespace std;
26using namespace flair::core;
27
28namespace flair {
29namespace gui {
30
31SendData::SendData(const LayoutPosition *position, string name, string type,
32 uint16_t default_periodms, bool default_enabled)
33 : Widget(position->getLayout(), name, type) {
34 pimpl_ = new SendData_impl();
35
36 pimpl_->send_size = 0;
37
38 // default refesh rate: (ms)
39 pimpl_->send_period = default_periodms;
40 pimpl_->is_enabled = default_enabled;
41
42 SetVolatileXmlProp("row", position->Row());
43 SetVolatileXmlProp("col", position->Col());
44 GetPersistentXmlProp("period", pimpl_->send_period);
45 SetPersistentXmlProp("period", pimpl_->send_period);
46 GetPersistentXmlProp("enabled", pimpl_->is_enabled);
47 SetPersistentXmlProp("enabled", pimpl_->is_enabled);
48
49 delete position;
50
51 if (getUiCom() != NULL) {
52 // register SendData for sending to ground station
53 getUiCom()->AddSendData(this);
54 // resume if necessary
55 getUiCom()->UpdateSendData(this);
56 }
57}
58
59SendData::~SendData() {
60 if (getUiCom() != NULL) {
61 // unregister SendData for sending to ground station
62 getUiCom()->RemoveSendData(this);
63 }
64
65 delete pimpl_;
66}
67
68void SendData::XmlEvent(void) {
69 uint16_t send_period;
70 bool is_enabled;
71 bool something_changed = false;
72
73 if (GetPersistentXmlProp("period", send_period) &&
74 GetPersistentXmlProp("enabled", is_enabled)) {
75 if (send_period != SendPeriod())
76 something_changed = true;
77 if (is_enabled != IsEnabled())
78 something_changed = true;
79 }
80
81 if (something_changed) {
82 getFrameworkManager()->BlockCom();
83
84 SetSendPeriod(send_period);
85 SetEnabled(is_enabled);
86
87 getFrameworkManager()->UpdateSendData(this);
88
89 // ack pour la station sol
90 // period and enabled are already in persistent prop
91 SetVolatileXmlProp("period", send_period);
92 SetVolatileXmlProp("enabled", is_enabled);
93 SendXml();
94
95 getFrameworkManager()->UnBlockCom();
96 }
97
98 ExtraXmlEvent();
99}
100
101size_t SendData::SendSize(void) const { return pimpl_->send_size; }
102
103uint16_t SendData::SendPeriod(void) const { return pimpl_->send_period; }
104
105bool SendData::IsEnabled(void) const { return pimpl_->is_enabled; }
106
107void SendData::SetEnabled(bool value) { pimpl_->is_enabled = value; }
108
109void SendData::SetSendSize(size_t value) {
110 pimpl_->send_size = value;
111
112 if (getUiCom() != NULL)
113 getUiCom()->UpdateDataToSendSize();
114}
115
116void SendData::SetSendPeriod(uint16_t value) { pimpl_->send_period = value; }
117
118} // end namespace core
119} // end namespace flair
Note: See TracBrowser for help on using the repository browser.