Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit b2a6fdb

Browse files
committed
Snapshot of a mostly complete Activities interface
Still lacking lots of implementation and a good testcase.
1 parent 3715300 commit b2a6fdb

File tree

13 files changed

+1528
-6
lines changed

13 files changed

+1528
-6
lines changed

Libs/libActivities/Activity.cpp

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/*
2+
* MacGitver
3+
* Copyright (C) 2012-2015 The MacGitver-Developers <[email protected]>
4+
*
5+
* (C) Sascha Cunz <[email protected]>
6+
* (C) Cunz RaD Ltd.
7+
*
8+
* This program is free software; you can redistribute it and/or modify it under the terms of the
9+
* GNU General Public License (Version 2) as published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
12+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along with this program; if
16+
* not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
#include "libActivities/Activity.hpp"
21+
#include "libActivities/ActivityPrivate.hpp"
22+
#include "libActivities/StepPrivate.hpp"
23+
#include "libActivities/ManagerPrivate.hpp"
24+
25+
namespace Activities
26+
{
27+
28+
namespace
29+
{
30+
void countTypes(const std::vector<StepData::Ptr>& steps, int& pending, int& running,
31+
int& success, int& error)
32+
{
33+
for (auto step : steps) {
34+
switch (step->mState) {
35+
case State::Unknown:
36+
case State::PartiallyFinishedWithErrors:
37+
break;
38+
39+
case State::Pending:
40+
pending++;
41+
break;
42+
43+
case State::InProgress:
44+
running++;
45+
break;
46+
47+
case State::Finished:
48+
success++;
49+
break;
50+
51+
case State::FinishedWithErrors:
52+
error++;
53+
break;
54+
}
55+
}
56+
}
57+
58+
State activityState(const std::vector<StepData::Ptr>& steps)
59+
{
60+
int pending = 0, running = 0, success = 0, error = 0, total = steps.size();
61+
countTypes(steps, pending, running, success, error);
62+
63+
if (total == 0 || pending == total) {
64+
return State::Pending;
65+
}
66+
67+
if (success == total) {
68+
return State::Finished;
69+
}
70+
71+
if (error == total) {
72+
return State::FinishedWithErrors;
73+
}
74+
75+
if (error > 0) {
76+
return State::PartiallyFinishedWithErrors;
77+
}
78+
79+
assert(running + success > 0);
80+
return State::InProgress;
81+
}
82+
}
83+
84+
ActivityData::ActivityData(const QString &display)
85+
: mGeneration(ManagerData::nextGeneration())
86+
, mState(State::Pending)
87+
, mIsDefunct(false)
88+
, mDisplay(display)
89+
, mCurProgress(0)
90+
, mMaxProgress(0)
91+
, mTotalCurProgress(0)
92+
, mTotalMaxProgress(0)
93+
{
94+
}
95+
96+
ActivityData::~ActivityData()
97+
{
98+
}
99+
100+
quint32 ActivityData::generation() const
101+
{
102+
return mGeneration;
103+
}
104+
105+
ActivityData::Ptr ActivityData::getptr()
106+
{
107+
return shared_from_this();
108+
}
109+
110+
std::unique_lock<std::mutex> ActivityData::uniqueLock() const
111+
{
112+
return std::unique_lock<std::mutex>(mMtx);
113+
}
114+
115+
bool ActivityData::isDefunct() const
116+
{
117+
std::lock_guard<std::mutex> _(mMtx);
118+
return mIsDefunct;
119+
}
120+
121+
void ActivityData::updated(const StepData::Ptr& step, std::unique_lock<std::mutex>& lock)
122+
{
123+
mTotalCurProgress = mCurProgress;
124+
mTotalMaxProgress = mMaxProgress;
125+
126+
for (StepData::Ptr step : mSteps) {
127+
128+
}
129+
}
130+
131+
void ActivityData::stepStarted(const StepData::Ptr& step, std::unique_lock<std::mutex> &lock)
132+
{
133+
State newState = activityState(mSteps);
134+
}
135+
136+
void ActivityData::stepFinished(const StepData::Ptr& step, bool failed, std::unique_lock<std::mutex> &lock)
137+
{
138+
State newState = activityState(mSteps);
139+
}
140+
141+
void ActivityData::logUpdated(const LogData::Ptr &log, std::unique_lock<std::mutex> &lock)
142+
{
143+
144+
}
145+
146+
bool ActivityData::isModalityRequired() const
147+
{
148+
return mForceModalDialog;
149+
}
150+
151+
// -----
152+
153+
Step::Vector Activity::steps() const
154+
{
155+
Step::Vector r;
156+
if (d) {
157+
std::lock_guard<std::mutex> _(d->mMtx);
158+
for (const StepData::Ptr& step : d->mSteps) {
159+
r.push_back(step);
160+
}
161+
}
162+
return r;
163+
}
164+
165+
bool Activity::isDefunct() const
166+
{
167+
if (d) {
168+
return d->isDefunct();
169+
}
170+
171+
return true;
172+
}
173+
174+
Log Activity::log() const
175+
{
176+
if (d) {
177+
std::lock_guard<std::mutex> _(d->mMtx);
178+
return {d->mLog};
179+
}
180+
return Log();
181+
}
182+
183+
#if 0
184+
void Activity::addStep(const Step::Ptr& step)
185+
{
186+
std::lock_guard<std::mutex> _(mMtx);
187+
std::shared_ptr<StepImpl> _step = std::static_pointer_cast<StepImpl>(step);
188+
189+
_step->setActivity(getptr());
190+
mSteps.push_back(step);
191+
}
192+
193+
#endif
194+
195+
}

Libs/libActivities/Activity.hpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* MacGitver
3+
* Copyright (C) 2012-2015 The MacGitver-Developers <[email protected]>
4+
*
5+
* (C) Sascha Cunz <[email protected]>
6+
* (C) Cunz RaD Ltd.
7+
*
8+
* This program is free software; you can redistribute it and/or modify it under the terms of the
9+
* GNU General Public License (Version 2) as published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
12+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along with this program; if
16+
* not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
#pragma once
21+
22+
#include "libActivities/Step.hpp"
23+
#include "libActivities/Log.hpp"
24+
25+
namespace Activities
26+
{
27+
28+
class ActivityData;
29+
30+
class ACTIVITIES_API Activity
31+
{
32+
public:
33+
using Vector = std::vector<Activity>;
34+
35+
public:
36+
Activity() = default;
37+
~Activity() = default;
38+
Activity(const Activity& o) : Activity(o.d) {}
39+
Activity(Activity&& o) : Activity(std::move(o.d)) {}
40+
Activity(const std::shared_ptr<ActivityData>& o) : d(o) {}
41+
Activity(std::shared_ptr<ActivityData>&& o) : d(std::move(o)) {}
42+
43+
public:
44+
Step::Vector steps() const;
45+
46+
public:
47+
State state() const;
48+
QString display() const;
49+
int curProgress() const;
50+
int maxProgress() const;
51+
int curOwnProgress() const;
52+
int maxOwnProgress() const;
53+
Log log() const;
54+
55+
public:
56+
void setState(State newState);
57+
void setDisplay(const QString& display);
58+
void setProgress(int cur, int max);
59+
60+
public:
61+
bool isDefunct() const;
62+
63+
private:
64+
std::shared_ptr<ActivityData> d;
65+
};
66+
67+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* MacGitver
3+
* Copyright (C) 2012-2015 The MacGitver-Developers <[email protected]>
4+
*
5+
* (C) Sascha Cunz <[email protected]>
6+
* (C) Cunz RaD Ltd.
7+
*
8+
* This program is free software; you can redistribute it and/or modify it under the terms of the
9+
* GNU General Public License (Version 2) as published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
12+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along with this program; if
16+
* not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
#pragma once
21+
22+
#include "libActivities/StepPrivate.hpp"
23+
#include "libActivities/LogPrivate.hpp"
24+
25+
namespace Activities
26+
{
27+
28+
class ActivityData
29+
: public std::enable_shared_from_this<ActivityData>
30+
{
31+
public:
32+
using Steps = std::vector<StepData::Ptr>;
33+
using Ptr = std::shared_ptr<ActivityData>;
34+
using Vector = std::vector<Ptr>;
35+
36+
public:
37+
ActivityData(const QString& display);
38+
~ActivityData();
39+
40+
public:
41+
quint32 generation() const;
42+
Ptr getptr();
43+
std::unique_lock<std::mutex> uniqueLock() const;
44+
45+
void updated(const StepData::Ptr& step, std::unique_lock<std::mutex> &lock);
46+
void stepStarted(const StepData::Ptr& step, std::unique_lock<std::mutex> &lock);
47+
void stepFinished(const StepData::Ptr& step, bool failed, std::unique_lock<std::mutex> &lock);
48+
void logUpdated(const LogData::Ptr& log, std::unique_lock<std::mutex>& lock);
49+
50+
public:
51+
bool isModalityRequired() const;
52+
bool isDefunct() const;
53+
54+
public:
55+
mutable std::mutex mMtx;
56+
quint32 mGeneration;
57+
State mState;
58+
bool mIsDefunct;
59+
Steps mSteps;
60+
LogData::Ptr mLog;
61+
QString mDisplay;
62+
int mCurProgress;
63+
int mMaxProgress;
64+
int mTotalCurProgress;
65+
int mTotalMaxProgress;
66+
bool mForceModalDialog;
67+
};
68+
69+
}

Libs/libActivities/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,25 @@ QT_PREPARE(Core)
66
SET( SRC_FILES
77

88
Manager.cpp
9+
Activity.cpp
10+
Step.cpp
11+
Log.cpp
912
)
1013

1114
SET( PUB_HDR_FILES
1215

1316
Api.hpp
1417
Manager.hpp
18+
Activity.hpp
19+
Step.hpp
20+
Log.hpp
1521
)
1622

1723
SET( PRI_HDR_FILES
24+
ManagerPrivate.hpp
25+
ActivityPrivate.hpp
26+
StepPrivate.hpp
27+
LogPrivate.hpp
1828
)
1929

2030
SET( HDR_FILES ${PRI_HDR_FILES} ${PUB_HDR_FILES} )

0 commit comments

Comments
 (0)