Page MenuHomePhorge

No OneTemporary

Size
24 KB
Referenced Files
None
Subscribers
None
diff --git a/Version_Max_07_05_2018_CMake/src/Channel.cpp b/Version_Max_07_05_2018_CMake/src/Channel.cpp
index 4e95c2b..2f66a50 100755
--- a/Version_Max_07_05_2018_CMake/src/Channel.cpp
+++ b/Version_Max_07_05_2018_CMake/src/Channel.cpp
@@ -1,360 +1,418 @@
#include "Channel.h"
#include <stdio.h>
#define MAX_BUFFER_LENGTH 100
-void Channel :: init_channel() {
- maxBufferLength = MAX_BUFFER_LENGTH;
- transferRate = MAX_BUFFER_LENGTH;
-}
-
-Channel :: Channel() {
- init_channel();
-}
-
-Channel :: Channel(std::string name) {
- set_name(name);
- init_channel();
-}
-
-bool Channel :: set_maxBufferLength(unsigned int maxBufferLength) {
- if(maxBufferLength <= MAX_BUFFER_LENGTH) {
- this->maxBufferLength = maxBufferLength;
- return true;
- }
- return false;
-}
-
-unsigned int Channel :: get_maxBufferLength() {
- return maxBufferLength;
-}
+#define PRINT
+//#define STOP_AFTER_CHANNEL_TRANSFARED
-unsigned int Channel :: get_avlInputBufferUp() {
- return maxBufferLength-lInputMsgBufferUp.size();
+void Channel ::init_channel() {
+ maxBufferLength = MAX_BUFFER_LENGTH;
+ transferRate = MAX_BUFFER_LENGTH;
}
-unsigned int Channel :: get_avlOutputBufferUp() {
- return maxBufferLength-lOutputMsgBufferUp.size();
-}
+Channel ::Channel() { init_channel(); }
-unsigned int Channel :: get_avlInputBufferDown() {
- return maxBufferLength-lInputMsgBufferDown.size();
+Channel ::Channel(std::string name) {
+ set_name(name);
+ init_channel();
}
-unsigned int Channel :: get_avlOutputBufferDown() {
- return maxBufferLength-lOutputMsgBufferDown.size();
-}
-
-bool Channel :: set_transferRate(unsigned int transferRate) {
- if(transferRate <= MAX_BUFFER_LENGTH) {
- this->transferRate = transferRate;
- return true;
- }
- return false;
+bool Channel ::set_maxBufferLength(unsigned int maxBufferLength) {
+ if (maxBufferLength <= MAX_BUFFER_LENGTH) {
+ this->maxBufferLength = maxBufferLength;
+ return true;
+ }
+ return false;
}
-unsigned int Channel :: get_transferRate() {
- return transferRate;
-}
-
-
-
-bool Channel :: add_msgAtBegin (list<Message*>* buffer, Message* message) {
- try {
- buffer->push_front(message);
- }
- catch(bad_alloc& error) {
- delete message;
- return false;
- }
- return true;
-}
-
-bool Channel :: del_msgAtBegin (list<Message*>* buffer) {
- try {
- /*
- printf("a\n");
- getchar();
- delete buffer->back();
- printf("b\n");
- getchar();
- */
- Message* first_Message = buffer->front();
- delete first_Message;
- buffer->pop_front();
- /*
- printf("c\n");
- getchar();
- */
- }
- catch(bad_alloc& error) {
- return false;
- }
- return true;
-}
+unsigned int Channel ::get_maxBufferLength() { return maxBufferLength; }
-bool Channel :: add_msgAtEnd (list<Message*>* buffer, Message* message) {
- try {
- buffer->push_back(message);
- }
- catch(bad_alloc& error) {
- cerr << "bad_alloc caught: " << error.what() << endl;
- delete message;
- return false;
- }
- return true;
+unsigned int Channel ::get_avlInputBufferUp() {
+ return maxBufferLength - lInputMsgBufferUp.size();
}
-bool del_msgAtEnd (list<Message*>* buffer) {
- try {
- Message* last_Message = buffer->back();
- delete last_Message;
- buffer->pop_back();
- }
- catch(bad_alloc& error) {
- return false;
- }
- return true;
-}
-
-bool Channel :: send_MsgUp(Message* message) {
- if(message != NULL) {
- if(transferRate == 0) {
- //TODO: at the moment only one packet (in the front) gets deleted if buffer is full. However, the whole message (instruction+value) should be deleted in case of a full buffer
- if(lOutputMsgBufferUp.size() == maxBufferLength) {
- del_msgAtBegin(&lOutputMsgBufferUp);
- }
- return add_msgAtEnd(&lOutputMsgBufferUp, message);
- }
- else {
- if(lInputMsgBufferUp.size() == maxBufferLength) {
- //TODO: at the moment only one packet (in the front) gets deleted if buffer is full. However, the whole message (instruction+value) should be deleted in case of a full buffer
- del_msgAtBegin(&lInputMsgBufferUp);
- }
- return add_msgAtEnd(&lInputMsgBufferUp, message);
- }
- }
-
- //TODO: check if NULL is a good default return value
- return NULL;
+unsigned int Channel ::get_avlOutputBufferUp() {
+ return maxBufferLength - lOutputMsgBufferUp.size();
}
-bool Channel :: send_MsgUp(float msg) {
- Message* message = new Message(msg);
- return send_MsgUp(message);
+unsigned int Channel ::get_avlInputBufferDown() {
+ return maxBufferLength - lInputMsgBufferDown.size();
}
-bool Channel :: send_MsgUp(int msg) {
- Message* message = new Message(msg);
- return send_MsgUp(message);
+unsigned int Channel ::get_avlOutputBufferDown() {
+ return maxBufferLength - lOutputMsgBufferDown.size();
}
-bool Channel :: get_MsgUp(float* msg) {
- if(isThereFloatMsgUp()) {
- float tempMsg;
- if(lOutputMsgBufferUp.front()->getMsg(&tempMsg)) {
- *msg = tempMsg;
- del_msgAtBegin(&lOutputMsgBufferUp);
- return true;
- }
- }
- return false;
+bool Channel ::set_transferRate(unsigned int transferRate) {
+ if (transferRate <= MAX_BUFFER_LENGTH) {
+ this->transferRate = transferRate;
+ return true;
+ }
+ return false;
}
-bool Channel :: get_MsgUp(int* msg) {
- if(isThereIntMsgUp()) {
- int tempMsg;
- if(lOutputMsgBufferUp.front()->getMsg(&tempMsg)) {
- *msg = tempMsg;
- del_msgAtBegin(&lOutputMsgBufferUp);
- return true;
- }
- }
- return false;
-}
+unsigned int Channel ::get_transferRate() { return transferRate; }
-bool Channel :: isThereFloatMsgUp() {
- if(lOutputMsgBufferUp.size() > 0 ) {
- if(lOutputMsgBufferUp.front() != NULL) {
- return lOutputMsgBufferUp.front()->isMsgFloat();
- }
- }
- return false;
+bool Channel ::add_msgAtBegin(list<Message *> *buffer, Message *message) {
+ try {
+ buffer->push_front(message);
+ } catch (bad_alloc &error) {
+ delete message;
+ return false;
+ }
+ return true;
}
-bool Channel :: isThereIntMsgUp() {
- if(lOutputMsgBufferUp.size() > 0 ) {
- if(lOutputMsgBufferUp.front() != NULL) {
- return lOutputMsgBufferUp.front()->isMsgInt();
- }
+//removes the message from the lsit and also delets the message
+bool Channel ::del_msgAtBegin(list<Message *> *buffer) {
+ try {
+ if (buffer != NULL && buffer->empty() == false) {
+ Message *first_Message = buffer->front();
+ // NOTE: I had to change the order of pop and delete. Before, i crashed.
+ buffer->pop_front();
+ delete first_Message;
}
- return false;
-}
-
-bool Channel :: send_MsgDown(Message* message) {
- if(message != NULL) {
- if(transferRate == 0) {
- if(lOutputMsgBufferDown.size() == maxBufferLength) {
- del_msgAtBegin(&lOutputMsgBufferDown);
- }
- return add_msgAtEnd(&lOutputMsgBufferDown, message);
- }
- else {
- if(lInputMsgBufferDown.size() == maxBufferLength) {
- del_msgAtBegin(&lInputMsgBufferDown);
- }
- return add_msgAtEnd(&lInputMsgBufferDown, message);
- }
+ } catch (bad_alloc &error) {
+ return false;
+ }
+ return true;
+}
+
+//just removes the message from the list
+bool Channel::rem_msgAtBegin(list<Message *> *buffer) {
+ try {
+ if (buffer != NULL && buffer->empty() == false) {
+ buffer->pop_front();
+ }
+ } catch (bad_alloc &error) {
+ return false;
+ }
+ return true;
+}
+
+bool Channel ::add_msgAtEnd(list<Message *> *buffer, Message *message) {
+ try {
+ buffer->push_back(message);
+ } catch (bad_alloc &error) {
+ cerr << "bad_alloc caught: " << error.what() << endl;
+ delete message;
+ return false;
+ }
+ return true;
+}
+
+bool del_msgAtEnd(list<Message *> *buffer) {
+ try {
+ Message *last_Message = buffer->back();
+ delete last_Message;
+ buffer->pop_back();
+ } catch (bad_alloc &error) {
+ return false;
+ }
+ return true;
+}
+
+bool Channel ::send_MsgUp(Message *message) {
+ if (message != NULL) {
+ if (transferRate == 0) {
+ // TODO: at the moment only one packet (in the front) gets deleted if
+ // buffer is full. However, the whole message (instruction+value) should
+ // be deleted in case of a full buffer
+ if (lOutputMsgBufferUp.size() == maxBufferLength) {
+ del_msgAtBegin(&lOutputMsgBufferUp);
+ }
+ return add_msgAtEnd(&lOutputMsgBufferUp, message);
+ } else {
+ if (lInputMsgBufferUp.size() == maxBufferLength) {
+ // TODO: at the moment only one packet (in the front) gets deleted if
+ // buffer is full. However, the whole message (instruction+value) should
+ // be deleted in case of a full buffer
+ del_msgAtBegin(&lInputMsgBufferUp);
+ }
+ return add_msgAtEnd(&lInputMsgBufferUp, message);
+ }
+ }
+
+ // TODO: check if NULL is a good default return value
+ return NULL;
+}
+
+bool Channel ::send_MsgUp(float msg) {
+ Message *message = new Message(msg);
+ return send_MsgUp(message);
+}
+
+bool Channel ::send_MsgUp(int msg) {
+ Message *message = new Message(msg);
+ return send_MsgUp(message);
+}
+
+// blub1
+bool Channel ::get_MsgUp(float *msg) {
+ if (isThereFloatMsgUp()) {
+ float tempMsg;
+ if (lOutputMsgBufferUp.front()->getMsg(&tempMsg)) {
+ *msg = tempMsg;
+ del_msgAtBegin(&lOutputMsgBufferUp);
+ return true;
+ }
+ }
+ return false;
+}
+
+bool Channel ::get_MsgUp(int *msg) {
+ if (isThereIntMsgUp()) {
+ int tempMsg;
+ if (lOutputMsgBufferUp.front()->getMsg(&tempMsg)) {
+ *msg = tempMsg;
+ del_msgAtBegin(&lOutputMsgBufferUp);
+ return true;
+ }
+ }
+ return false;
+}
+
+bool Channel ::isThereFloatMsgUp() {
+ if (lOutputMsgBufferUp.size() > 0) {
+ if (lOutputMsgBufferUp.front() != NULL) {
+ return lOutputMsgBufferUp.front()->isMsgFloat();
+ }
+ }
+ return false;
+}
+
+bool Channel ::isThereIntMsgUp() {
+ printf("a\n");
+ if (lOutputMsgBufferUp.size() > 0) {
+ printf("b\n");
+ if (lOutputMsgBufferUp.front() != NULL) {
+ printf("c\n");
+ return lOutputMsgBufferUp.front()->isMsgInt();
+ }
+ }
+ return false;
+}
+
+bool Channel ::send_MsgDown(Message *message) {
+ if (message != NULL) {
+ if (transferRate == 0) {
+ if (lOutputMsgBufferDown.size() == maxBufferLength) {
+ del_msgAtBegin(&lOutputMsgBufferDown);
+ }
+ return add_msgAtEnd(&lOutputMsgBufferDown, message);
+ } else {
+ if (lInputMsgBufferDown.size() == maxBufferLength) {
+ del_msgAtBegin(&lInputMsgBufferDown);
+ }
+ return add_msgAtEnd(&lInputMsgBufferDown, message);
+ }
+ }
+
+ // TODO: check if NULL is a good default return value
+ return NULL;
+}
+
+bool Channel ::send_MsgDown(float msg) {
+ Message *message = new Message(msg);
+ return send_MsgDown(message);
+}
+
+bool Channel ::send_MsgDown(int msg) {
+ Message *message = new Message(msg);
+ return send_MsgDown(message);
+}
+
+bool Channel ::get_MsgDown(float *msg) {
+ if (isThereFloatMsgDown()) {
+ float tempMsg;
+ if (lOutputMsgBufferDown.front()->getMsg(&tempMsg)) {
+ *msg = tempMsg;
+ del_msgAtBegin(&lOutputMsgBufferDown);
+ return true;
+ }
+ }
+ return false;
+}
+
+bool Channel ::get_MsgDown(int *msg) {
+ if (isThereIntMsgDown()) {
+ int tempMsg;
+ if (lOutputMsgBufferDown.front()->getMsg(&tempMsg)) {
+ *msg = tempMsg;
+ del_msgAtBegin(&lOutputMsgBufferDown);
+ return true;
+ }
+ }
+ return false;
+}
+
+bool Channel ::isThereFloatMsgDown() {
+ if (lOutputMsgBufferDown.size() > 0) {
+ if (lOutputMsgBufferDown.front() != NULL) {
+ return lOutputMsgBufferDown.front()->isMsgFloat();
+ }
+ }
+ return false;
+}
+
+bool Channel ::isThereIntMsgDown() {
+ if (lOutputMsgBufferDown.size() > 0) {
+ if (lOutputMsgBufferDown.front() != NULL) {
+ return lOutputMsgBufferDown.front()->isMsgInt();
+ }
+ }
+ return false;
+}
+
+bool Channel ::transferMsgs(list<Message *> *dest_buffer,
+ list<Message *> *src_buffer) {
+ unsigned int NumOfMsgsToMove;
+
+ if (transferRate <= src_buffer->size()) {
+ NumOfMsgsToMove = transferRate;
+ } else {
+ NumOfMsgsToMove = src_buffer->size();
+ }
+
+ if (NumOfMsgsToMove <= maxBufferLength - dest_buffer->size()) {
+ for (unsigned int i = 0; i < NumOfMsgsToMove; i++) {
+ if (add_msgAtEnd(dest_buffer, src_buffer->front())) {
+#ifdef PRINT
+ if (src_buffer->front()->isMsgFloat()) {
+ float m;
+ dest_buffer->back()->getMsg(&m);
+ printf("Sent: %f - Channel %s\n", m, name.c_str());
+ } else if (src_buffer->front()->isMsgInt()) {
+ int m;
+ dest_buffer->back()->getMsg(&m);
+ printf("Sent: %i - Channel %s\n", m, name.c_str());
+ } else {
+ printf("nothing!!!!!!!!!!!\n");
+ }
+ getchar();
+#endif // PRINT
+ //just remove the message from the source buffer, don't delete it, it is still needed in the output buffer!
+ if (!rem_msgAtBegin(src_buffer)) {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+}
+
+bool Channel ::trigger() {
+
+#ifdef PRINT
+ printf("Before - in_up %u, out_up %u, in_dn %u, out_dn %u - Channel %s\n",
+ (int)lInputMsgBufferUp.size(), (int)lOutputMsgBufferUp.size(),
+ (int)lInputMsgBufferDown.size(), (int)lOutputMsgBufferDown.size(),
+ name.c_str());
+#endif // PRINT
+
+ // TODO: there are two time the same transferMsgs functions called with
+ // exactly the same buffers.. I guess one side should be with "...BufferDown"
+ bool flag_worked = transferMsgs(&lOutputMsgBufferUp, &lInputMsgBufferUp) &&
+ transferMsgs(&lOutputMsgBufferDown, &lInputMsgBufferDown);
+ // bool flag_worked = transferMsgs(&lOutputMsgBufferUp, &lInputMsgBufferUp) &&
+ // transferMsgs(&lOutputMsgBufferUp, &lInputMsgBufferUp);
+#ifdef PRINT
+ printf("After - in_up %u, out_up %u, in_dn %u, out_dn %u - Channel %s\n\n",
+ (int)lInputMsgBufferUp.size(), (int)lOutputMsgBufferUp.size(),
+ (int)lInputMsgBufferDown.size(), (int)lOutputMsgBufferDown.size(),
+ name.c_str());
+
+ printf("outputBufferUp filled with:\n");
+ for (auto msg : lOutputMsgBufferUp) {
+ if (msg == NULL) {
+ printf("msg = NULL!!!!!!!!!!!!!!!!!!!!!!!!!\n");
+ } else {
+
+ if (msg->isMsgFloat()) {
+ float m;
+ msg->getMsg(&m);
+ printf("Send: %f - Channel %s\n", m, name.c_str());
+ } else if (msg->isMsgInt()) {
+ int m;
+ msg->getMsg(&m);
+ printf("Send: %i - Channel %s\n", m, name.c_str());
+ } else {
+ printf("empty!\n");
+ }
}
-
- // TODO: check if NULL is a good default return value
- return NULL;
-}
-
-bool Channel :: send_MsgDown(float msg) {
- Message* message = new Message(msg);
- return send_MsgDown(message);
-}
-
-bool Channel :: send_MsgDown(int msg) {
- Message* message = new Message(msg);
- return send_MsgDown(message);
-}
-
-bool Channel :: get_MsgDown(float* msg) {
- if(isThereFloatMsgDown()) {
- float tempMsg;
- if(lOutputMsgBufferDown.front()->getMsg(&tempMsg)) {
- *msg = tempMsg;
- del_msgAtBegin(&lOutputMsgBufferDown);
- return true;
- }
- }
- return false;
-}
-
-bool Channel :: get_MsgDown(int* msg) {
- if(isThereIntMsgDown()) {
- int tempMsg;
- if(lOutputMsgBufferDown.front()->getMsg(&tempMsg)) {
- *msg = tempMsg;
- del_msgAtBegin(&lOutputMsgBufferDown);
- return true;
- }
- }
- return false;
-}
-
-bool Channel :: isThereFloatMsgDown() {
- if(lOutputMsgBufferDown.size() > 0 ) {
- if(lOutputMsgBufferDown.front() != NULL) {
- return lOutputMsgBufferDown.front()->isMsgFloat();
- }
- }
- return false;
-}
-
-bool Channel :: isThereIntMsgDown() {
- if(lOutputMsgBufferDown.size() > 0 ) {
- if(lOutputMsgBufferDown.front() != NULL) {
- return lOutputMsgBufferDown.front()->isMsgInt();
- }
- }
- return false;
-}
-
-bool Channel :: transferMsgs(list<Message*>* dest_buffer, list<Message*>* src_buffer) {
- unsigned int NumOfMsgsToMove;
-
- if(transferRate <= src_buffer->size()) {
- NumOfMsgsToMove = transferRate;
- }
- else {
- NumOfMsgsToMove = src_buffer->size();
- }
-
- if(NumOfMsgsToMove <= maxBufferLength-dest_buffer->size()) {
- for(unsigned int i=0; i<NumOfMsgsToMove; i++) {
- if(add_msgAtEnd(dest_buffer, src_buffer->front())) {
- if(!del_msgAtBegin(src_buffer)) {
- return false;
- }
- }
- else {
- return false;
- }
- }
- return true;
- }
- return false;
-}
-
-bool Channel :: trigger() {
- bool flag_worked = transferMsgs(&lOutputMsgBufferUp, &lInputMsgBufferUp) && transferMsgs(&lOutputMsgBufferUp, &lInputMsgBufferUp);
- //printf("Channel %s: in_up %u, out_up %u, in_dn %u, out_dn %u,\n", name, lInputMsgBufferUp.size(), lOutputMsgBufferUp.size(), lInputMsgBufferDown.size(), lOutputMsgBufferDown.size());
- return flag_worked;
-
-}
-
-bool Channel :: delete_all_InputMsgBufferUp()
-{
- Message* cur_Message;
- unsigned int cur_index_Message = 0;
- unsigned int size_li_Inp_MsgBufUp = lInputMsgBufferUp.size();
- //changed - "cur_index_Message" to "cur_index_Message++" .. is it right?
- for(cur_index_Message = 0; cur_index_Message < size_li_Inp_MsgBufUp; cur_index_Message++){
- cur_Message = lInputMsgBufferUp.front();
- delete cur_Message;
- lInputMsgBufferUp.pop_front();
- }
-
- return true; //added by Ali, it is an error in VS.
-}
-
-bool Channel :: delete_all_OuputMsgBufferUp()
-{
- Message* cur_Message;
- unsigned int cur_index_Message = 0;
- unsigned int size_li_Out_MsgBufUp = lOutputMsgBufferUp.size();
- //changed - "cur_index_Message" to "cur_index_Message++" .. is it right?
- for(cur_index_Message = 0; cur_index_Message < size_li_Out_MsgBufUp; cur_index_Message++){
- cur_Message = lOutputMsgBufferUp.front();
- delete cur_Message;
- lOutputMsgBufferUp.pop_front();
- }
- return true; //added by Ali, it is an error in VS.
-}
-bool Channel :: delete_all_InputMsgBufferDown()
-{
- Message* cur_Message;
- unsigned int cur_index_Message = 0;
- unsigned int size_li_Out_MsgBufDown = lInputMsgBufferDown.size();
- // changed - "cur_index_Message" to "cur_index_Message++" .. is it right?
- for(cur_index_Message = 0; cur_index_Message < size_li_Out_MsgBufDown; cur_index_Message++){
- cur_Message = lInputMsgBufferDown.front();
- delete cur_Message;
- lInputMsgBufferDown.pop_front();
- }
- return true; //added by Ali, it is an error in VS.
-}
-bool Channel :: delete_all_OutputMsgBufferDown()
-{
- Message* cur_Message;
- unsigned int cur_index_Message = 0;
- unsigned int size_li_Out_MsgBufDown = lOutputMsgBufferDown.size();
- //changed - "cur_index_Message" to "cur_index_Message++" .. is it right?
- for(cur_index_Message = 0; cur_index_Message < size_li_Out_MsgBufDown; cur_index_Message++){
- cur_Message = lOutputMsgBufferDown.front();
- delete cur_Message;
- lOutputMsgBufferDown.pop_front();
- }
- return true; //added by Ali, it is an error in VS.
-}
-
-Channel :: ~Channel()
-{
- delete_all_InputMsgBufferUp();
- delete_all_OuputMsgBufferUp();
- delete_all_InputMsgBufferDown();
- delete_all_OutputMsgBufferDown();
+ }
+
+#endif // PRINT
+
+#ifdef STOP_AFTER_CHANNEL_TRANSFARED
+ getchar();
+#endif // #ifdef STOP_AFTER_CHANNEL_TRANSFARED
+
+ return flag_worked;
+}
+
+bool Channel ::delete_all_InputMsgBufferUp() {
+ Message *cur_Message;
+ unsigned int cur_index_Message = 0;
+ unsigned int size_li_Inp_MsgBufUp = lInputMsgBufferUp.size();
+ // changed - "cur_index_Message" to "cur_index_Message++" .. is it right?
+ for (cur_index_Message = 0; cur_index_Message < size_li_Inp_MsgBufUp;
+ cur_index_Message++) {
+ cur_Message = lInputMsgBufferUp.front();
+ delete cur_Message;
+ lInputMsgBufferUp.pop_front();
+ }
+
+ return true; // added by Ali, it is an error in VS.
+}
+
+bool Channel ::delete_all_OuputMsgBufferUp() {
+ Message *cur_Message;
+ unsigned int cur_index_Message = 0;
+ unsigned int size_li_Out_MsgBufUp = lOutputMsgBufferUp.size();
+ // changed - "cur_index_Message" to "cur_index_Message++" .. is it right?
+ for (cur_index_Message = 0; cur_index_Message < size_li_Out_MsgBufUp;
+ cur_index_Message++) {
+ cur_Message = lOutputMsgBufferUp.front();
+ delete cur_Message;
+ lOutputMsgBufferUp.pop_front();
+ }
+ return true; // added by Ali, it is an error in VS.
+}
+bool Channel ::delete_all_InputMsgBufferDown() {
+ Message *cur_Message;
+ unsigned int cur_index_Message = 0;
+ unsigned int size_li_Out_MsgBufDown = lInputMsgBufferDown.size();
+ // changed - "cur_index_Message" to "cur_index_Message++" .. is it right?
+ for (cur_index_Message = 0; cur_index_Message < size_li_Out_MsgBufDown;
+ cur_index_Message++) {
+ cur_Message = lInputMsgBufferDown.front();
+ delete cur_Message;
+ lInputMsgBufferDown.pop_front();
+ }
+ return true; // added by Ali, it is an error in VS.
+}
+bool Channel ::delete_all_OutputMsgBufferDown() {
+ Message *cur_Message;
+ unsigned int cur_index_Message = 0;
+ unsigned int size_li_Out_MsgBufDown = lOutputMsgBufferDown.size();
+ // changed - "cur_index_Message" to "cur_index_Message++" .. is it right?
+ for (cur_index_Message = 0; cur_index_Message < size_li_Out_MsgBufDown;
+ cur_index_Message++) {
+ cur_Message = lOutputMsgBufferDown.front();
+ delete cur_Message;
+ lOutputMsgBufferDown.pop_front();
+ }
+ return true; // added by Ali, it is an error in VS.
+}
+
+Channel ::~Channel() {
+ delete_all_InputMsgBufferUp();
+ delete_all_OuputMsgBufferUp();
+ delete_all_InputMsgBufferDown();
+ delete_all_OutputMsgBufferDown();
}
diff --git a/Version_Max_07_05_2018_CMake/src/Channel.h b/Version_Max_07_05_2018_CMake/src/Channel.h
index 7cb56ad..ba5f838 100755
--- a/Version_Max_07_05_2018_CMake/src/Channel.h
+++ b/Version_Max_07_05_2018_CMake/src/Channel.h
@@ -1,81 +1,82 @@
#ifndef CHANNEL_HEADERFILE
#define CHANNEL_HEADERFILE
#include <list>
#include <new>
#include <iostream>
#include "Message.h"
#include "Module.h"
#define MAX_BUFFER_LENGTH 100
#define OPEN NULL
using namespace std;
class Channel : public Module {
private:
list<Message*> lInputMsgBufferUp;
list<Message*> lOutputMsgBufferUp;
list<Message*> lInputMsgBufferDown;
list<Message*> lOutputMsgBufferDown;
unsigned int maxBufferLength;
unsigned int transferRate;
void init_channel();
bool add_msgAtBegin (list<Message*>* buffer, Message* message);
bool del_msgAtBegin (list<Message*>* buffer);
+ bool rem_msgAtBegin(list<Message *> *buffer);
bool add_msgAtEnd (list<Message*>* buffer, Message* message);
- bool del_msgAtEnd (list<Message*>* buffer);
+ //bool del_msgAtEnd (list<Message*>* buffer);
bool delete_all_InputMsgBufferUp();
bool delete_all_OuputMsgBufferUp();
bool delete_all_InputMsgBufferDown();
bool delete_all_OutputMsgBufferDown();
public:
Channel();
Channel(std::string name);
bool set_maxBufferLength(unsigned int maxBufferLength);
unsigned int get_maxBufferLength();
unsigned int get_avlInputBufferUp();
unsigned int get_avlOutputBufferUp();
unsigned int get_avlInputBufferDown();
unsigned int get_avlOutputBufferDown();
bool set_transferRate(unsigned int transferRate);
unsigned int get_transferRate();
bool send_MsgUp(Message* message);
bool send_MsgUp(float msg);
bool send_MsgUp(int msg);
bool get_MsgUp(float* msg);
bool get_MsgUp(int* msg);
bool isThereFloatMsgUp();
bool isThereIntMsgUp();
bool send_MsgDown(Message* message);
bool send_MsgDown(float msg);
bool send_MsgDown(int msg);
bool get_MsgDown(float* msg);
bool get_MsgDown(int* msg);
bool isThereFloatMsgDown();
bool isThereIntMsgDown();
bool trigger();
bool transferMsgs(list<Message*>* dest_buffer, list<Message*>* src_buffer);
~Channel();
};
#endif

File Metadata

Mime Type
text/x-diff
Expires
Sun, Apr 27, 12:52 PM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
134501
Default Alt Text
(24 KB)

Event Timeline