Debian Codegraph @

Source/Concurrent/Callback/CCallbackRememberLinkedExecuter.cpp

raw
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 "CCallbackRememberLinkedExecuter.h"
22
23
24
25 namespace Konclude {
26
27 namespace Concurrent {
28
29 namespace Callback {
30
31
32
33 CCallbackRememberLinkedExecuter::CCallbackRememberLinkedExecuter() {
34 mCallbackLinker = nullptr;
35 mCalledCallbackStop = nullptr;
36 mCallbackExecuted = false;
37 }
38
39
40 CCallbackRememberLinkedExecuter::~CCallbackRememberLinkedExecuter() {
41 }
42
43 void CCallbackRememberLinkedExecuter::doCallback() {
44 mCallbackExecuted = true;
45 CCallbackData* callbackStop = mCalledCallbackStop;
46 CCallbackData* newCallbackStop = mCallbackLinker;
47 mCalledCallbackStop = newCallbackStop;
48 CCallbackData* callbackIt = newCallbackStop;
49 while (callbackIt && callbackIt != callbackStop) {
50 CCallbackData* callback = callbackIt;
51 callbackIt = callbackIt->getNext();
52 callback->doCallback();
53 }
54 }
55
56
57 qint64 CCallbackRememberLinkedExecuter::getCallbackCount() {
58 cint64 count = 0;
59 if (mCallbackLinker) {
60 count = mCallbackLinker->getCount();
61 }
62 return count;
63 }
64
65
66
67 CCallbackRememberLinkedExecuter* CCallbackRememberLinkedExecuter::addCallbacks(CCallbackData* callbackData) {
68 if (mCallbackExecuted) {
69 CCallbackData* callbackIt = callbackData;
70 while (callbackIt) {
71 CCallbackData* callback = callbackIt;
72 callbackIt = callbackIt->getNext();
73 callback->doCallback();
74 }
75 } else {
76 if (callbackData) {
77 mCallbackLinker = callbackData->append(mCallbackLinker);
78 }
79 if (mCallbackExecuted) {
80 doCallback();
81 }
82 }
83 return this;
84 }
85
86 CCallbackRememberLinkedExecuter* CCallbackRememberLinkedExecuter::removeCallbacks(CCallbackData* callbackData) {
87 CCallbackData* callbackIt = callbackData;
88 while (callbackIt) {
89 if (mCallbackLinker) {
90 mCallbackLinker = mCallbackLinker->removeOne(callbackData);
91 }
92 callbackIt = callbackIt->getNext();
93 }
94 return this;
95 }
96
97 }; // end namespace Callback
98
99 }; // end namespace Concurrent
100
101 }; // end namespace Konclude