| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "CEventLinkerChannel.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Concurrent { |
| 27 |
|
| 28 |
|
| 29 |
CEventLinkerChannel::CEventLinkerChannel(CThreadActivator* threadActivator, double channelPriority) { |
| 30 |
mThreadActivator = threadActivator; |
| 31 |
mPostedEventLinker = nullptr; |
| 32 |
mLastTakedPostEventLinker = nullptr; |
| 33 |
mLastPostedEventLinker = nullptr; |
| 34 |
mLastTakedDuplicatedPostEventLinker = nullptr; |
| 35 |
|
| 36 |
acquiredLinkerCount = 0; |
| 37 |
fetchedLinkerCount = 0; |
| 38 |
postedLinkerCount = 0; |
| 39 |
|
| 40 |
mChannelPriority = channelPriority; |
| 41 |
} |
| 42 |
|
| 43 |
CEventLinkerChannel::~CEventLinkerChannel() { |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
bool CEventLinkerChannel::checkPostEvent(CEvent* processingEvent) { |
| 48 |
return processingEvent != mLastTakedPostEventLinker; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
CEventChannel* CEventLinkerChannel::postEvent(CEvent* processingEvent) { |
| 53 |
mLastPostedEventLinker = mPostedEventLinker; |
| 54 |
CEventLinker* newEventPostLinker = processingEvent; |
| 55 |
processingEvent->setEventChannelPriority(mChannelPriority); |
| 56 |
//if (newEventPostLinker == mLastTakedPostEventLinker) { |
| 57 |
// mLastTakedDuplicatedPostEventLinker = newEventPostLinker; |
| 58 |
//} |
| 59 |
if (mPostedEventLinker != newEventPostLinker) { |
| 60 |
newEventPostLinker->initEventLinker(processingEvent,mPostedEventLinker); |
| 61 |
mPostedEventLinker = newEventPostLinker; |
| 62 |
} else { |
| 63 |
// write access to mLastTakedPostEventLinker is safe only in this case |
| 64 |
newEventPostLinker->initEventLinker(processingEvent,nullptr); |
| 65 |
mPostedEventLinker = newEventPostLinker; |
| 66 |
mLastTakedPostEventLinker = nullptr; |
| 67 |
} |
| 68 |
++postedLinkerCount; |
| 69 |
mThreadActivator->signalizeEvent(); |
| 70 |
return this; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
CEventLinker* CEventLinkerChannel::takeEvents(CEventLinker* addEventLinker) { |
| 75 |
// reverse stored event order, take all events |
| 76 |
CEventLinker* tmpEventPostLinker = mPostedEventLinker; |
| 77 |
//bool duplicatedStopp = tmpEventPostLinker == mLastTakedDuplicatedPostEventLinker; |
| 78 |
//mLastTakedDuplicatedPostEventLinker = nullptr; |
| 79 |
CEventLinker* tmpNextLastPostEventLinker = tmpEventPostLinker; |
| 80 |
CEventLinker* tmpAddEventLinker = nullptr; |
| 81 |
while (tmpEventPostLinker && (tmpEventPostLinker != mLastTakedPostEventLinker /*|| duplicatedStopp*/)) { |
| 82 |
//if (tmpEventPostLinker == mLastTakedPostEventLinker) { |
| 83 |
// duplicatedStopp = false; |
| 84 |
//} |
| 85 |
tmpAddEventLinker = tmpEventPostLinker; |
| 86 |
tmpEventPostLinker = tmpEventPostLinker->getNextEventLinker(); |
| 87 |
addEventLinker = tmpAddEventLinker->setNextEventLinker(addEventLinker); |
| 88 |
++fetchedLinkerCount; |
| 89 |
} |
| 90 |
if (tmpNextLastPostEventLinker != mLastTakedPostEventLinker) { |
| 91 |
mLastTakedPostEventLinker = tmpNextLastPostEventLinker; |
| 92 |
} |
| 93 |
return addEventLinker; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
bool CEventLinkerChannel::hasEvents() { |
| 99 |
return mLastTakedPostEventLinker != mPostedEventLinker; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
double CEventLinkerChannel::getChannelPriority() { |
| 105 |
return mChannelPriority; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
}; // end namespace Concurrent |
| 110 |
|
| 111 |
}; // end namespace Konclude |
| 112 |
|