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

libActivities #37

Open
wants to merge 36 commits into
base: repoman
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f57c961
Move AutoRefresher out of RM-namespace
scunz May 10, 2015
1af99a0
Make AutoRefresher internal
scunz Mar 22, 2015
e722ebe
Move refresher instance into MacGitver
scunz Apr 17, 2015
1ad1e9c
Change RepoMan's "Set" to "List" everywhere
scunz Mar 22, 2015
77517e6
Move RepoMan Config Page to Config-Area
scunz May 10, 2015
97a29e7
Move some RepoMan code around
scunz Mar 21, 2015
9ff3da1
Turn RM::ObjType into an Enum Class
scunz May 11, 2015
d16922c
Move BasePrivate to own .cpp file
scunz May 11, 2015
fa24fc0
Be explicit about namespace of Dumper class
scunz May 12, 2015
eff4d8d
Move Branch & Head Private's to own cpp
scunz May 12, 2015
b1022f3
Temporary code
scunz Apr 21, 2015
43dc7ea
Fixup to "Temporary Code" :(
scunz May 10, 2015
9a902ce
Adjustments
scunz May 11, 2015
4a4afc4
Split off RepoMan & make everything compile at least
scunz Apr 11, 2015
87d4364
Repoman Events
scunz Apr 19, 2015
f9d4801
Fix some Compat-Event compile issues
scunz Apr 19, 2015
6ecc29c
Logging Channel for Git
scunz Apr 21, 2015
c635fcc
Add Service Runner into the backend
scunz May 9, 2015
b6fb03a
Add: OpenRepository Service
scunz May 9, 2015
0fa9c3e
Invoke OpenRepository service
scunz May 10, 2015
63d17bc
Add: RefreshRepository Service
scunz May 9, 2015
da0ed09
Add: refresh() method to RepoMan
scunz May 10, 2015
bf7ceff
Core files for libActivities
scunz Apr 26, 2015
431e98b
Snapshot of a mostly complete Activities interface
scunz May 8, 2015
33f1e00
Should fix Linux build
scunz May 9, 2015
226c351
Fixup: Remove unused code
scunz May 10, 2015
6aa8e7c
Step creation
scunz May 10, 2015
e2dd1ed
Fixup: Remove deadlock
scunz May 10, 2015
c3ef9d8
Actually implement state getters in Activity
scunz May 10, 2015
3a7d25f
Fixup: "return {}" to avoid naming the constructor
scunz May 10, 2015
5bf8aee
Public method to request opening of Progress Dialog
scunz May 10, 2015
9ded4fd
Fixup: Inline comment (Manager Priv.hpp)
scunz May 10, 2015
948f8e9
Activities: use Q_ASSERT instead of assert (fix build on linux)
antis81 May 12, 2015
ee2797c
RepoMan: use Q_ASSERT instead of assert (fix build on linux)
antis81 May 12, 2015
bf08429
RepoMan: fix include pathes for case sensitive file systems
antis81 May 12, 2015
892d60b
RepoMan: fix missing include
antis81 May 12, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ENABLE_TESTING()
SET(UTILS_APP_NAME MacGitver)

RAD_DEFINE_VERSION(MACGITVER_CORE 0 0 1)
RAD_DEFINE_VERSION(REPOMAN 0 0 1)

ADD_SUBDIRECTORY(CfgComp)

Expand Down
3 changes: 3 additions & 0 deletions Libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ INCLUDE_DIRECTORIES( BEFORE
)

ADD_SUBDIRECTORY(libLogger)
ADD_SUBDIRECTORY(libActivities)
ADD_SUBDIRECTORY(libDiffViews)
ADD_SUBDIRECTORY(libRepoMan)
ADD_SUBDIRECTORY(libMacGitverCore)

259 changes: 259 additions & 0 deletions Libs/libActivities/Activity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
/*
* MacGitver
* Copyright (C) 2012-2015 The MacGitver-Developers <[email protected]>
*
* (C) Sascha Cunz <[email protected]>
* (C) Cunz RaD Ltd.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License (Version 2) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if
* not, see <http://www.gnu.org/licenses/>.
*
*/

#include "libActivities/Activity.hpp"
#include "libActivities/ActivityPrivate.hpp"
#include "libActivities/StepPrivate.hpp"
#include "libActivities/ManagerPrivate.hpp"

namespace Activities
{

namespace
{
void countTypes(const std::vector<StepData::Ptr>& steps, int& pending, int& running,
int& success, int& error)
{
for (auto step : steps) {
switch (step->mState) {
case State::Unknown:
case State::PartiallyFinishedWithErrors:
break;

case State::Pending:
pending++;
break;

case State::InProgress:
running++;
break;

case State::Finished:
success++;
break;

case State::FinishedWithErrors:
error++;
break;
}
}
}

State activityState(const std::vector<StepData::Ptr>& steps)
{
int pending = 0, running = 0, success = 0, error = 0, total = steps.size();
countTypes(steps, pending, running, success, error);

if (total == 0 || pending == total) {
return State::Pending;
}

if (success == total) {
return State::Finished;
}

if (error == total) {
return State::FinishedWithErrors;
}

if (error > 0) {
return State::PartiallyFinishedWithErrors;
}

Q_ASSERT(running + success > 0);
return State::InProgress;
}
}

ActivityData::ActivityData(const QString &display)
: mGeneration(ManagerData::nextGeneration())
, mState(State::Pending)
, mIsDefunct(false)
, mDisplay(display)
, mCurProgress(0)
, mMaxProgress(0)
, mTotalCurProgress(0)
, mTotalMaxProgress(0)
{
}

ActivityData::~ActivityData()
{
}

quint32 ActivityData::generation() const
{
return mGeneration;
}

ActivityData::Ptr ActivityData::getptr()
{
return shared_from_this();
}

std::unique_lock<std::mutex> ActivityData::uniqueLock() const
{
return std::unique_lock<std::mutex>(mMtx);
}

bool ActivityData::isDefunct() const
{
std::lock_guard<std::mutex> _(mMtx);
return mIsDefunct;
}

void ActivityData::updated(const StepData::Ptr& step, std::unique_lock<std::mutex>& lock)
{
mTotalCurProgress = mCurProgress;
mTotalMaxProgress = mMaxProgress;

for (StepData::Ptr step : mSteps) {

}
}

void ActivityData::stepStarted(const StepData::Ptr& step, std::unique_lock<std::mutex> &lock)
{
State newState = activityState(mSteps);
}

void ActivityData::stepFinished(const StepData::Ptr& step, bool failed, std::unique_lock<std::mutex> &lock)
{
State newState = activityState(mSteps);
}

void ActivityData::logUpdated(const LogData::Ptr &log, std::unique_lock<std::mutex> &lock)
{

}

bool ActivityData::isModalityRequired() const
{
return mForceModalDialog;
}

// -----

Step::Vector Activity::steps() const
{
Step::Vector r;
if (d) {
std::lock_guard<std::mutex> _(d->mMtx);
for (const StepData::Ptr& step : d->mSteps) {
r.push_back(step);
}
}
return r;
}

bool Activity::isDefunct() const
{
if (d) {
return d->isDefunct();
}

return true;
}

Log Activity::log() const
{
if (d) {
std::lock_guard<std::mutex> _(d->mMtx);
return {d->mLog};
}
return {};
}

State Activity::state() const
{
if (d) {
std::lock_guard<std::mutex> _(d->mMtx);
return d->mState;
}

return State::Unknown;
}

QString Activity::display() const
{
if (d) {
std::lock_guard<std::mutex> _(d->mMtx);
return d->mDisplay;
}

return {};
}

int Activity::curProgress() const
{
if (d) {
std::lock_guard<std::mutex> _(d->mMtx);
return d->mTotalCurProgress;
}

return 0;
}

int Activity::maxProgress() const
{
if (d) {
std::lock_guard<std::mutex> _(d->mMtx);
return d->mTotalMaxProgress;
}

return 0;
}

int Activity::curOwnProgress() const
{
if (d) {
std::lock_guard<std::mutex> _(d->mMtx);
return d->mCurProgress;
}

return 0;
}

int Activity::maxOwnProgress() const
{
if (d) {
std::lock_guard<std::mutex> _(d->mMtx);
return d->mMaxProgress;
}

return 0;
}

Step Activity::createStep(const QString& displayName)
{
if (d) {
std::lock_guard<std::mutex> _(d->mMtx);

StepData::Ptr sd = StepData::create(d->getptr(), displayName);
d->mSteps.push_back(sd);

ManagerData::instance()->enqueue(EventTypes::StepAdded, d->getptr(), sd);

return {sd};
}

return {};
}

}
68 changes: 68 additions & 0 deletions Libs/libActivities/Activity.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* MacGitver
* Copyright (C) 2012-2015 The MacGitver-Developers <[email protected]>
*
* (C) Sascha Cunz <[email protected]>
* (C) Cunz RaD Ltd.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License (Version 2) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if
* not, see <http://www.gnu.org/licenses/>.
*
*/

#pragma once

#include "libActivities/Step.hpp"
#include "libActivities/Log.hpp"

namespace Activities
{

class ActivityData;

class ACTIVITIES_API Activity
{
public:
using Vector = std::vector<Activity>;

public:
Activity() = default;
~Activity() = default;
Activity(const Activity& o) : Activity(o.d) {}
Activity(Activity&& o) : Activity(std::move(o.d)) {}
Activity(const std::shared_ptr<ActivityData>& o) : d(o) {}
Activity(std::shared_ptr<ActivityData>&& o) : d(std::move(o)) {}

public:
Step::Vector steps() const;
Step createStep(const QString& displayName);

public:
State state() const;
QString display() const;
int curProgress() const;
int maxProgress() const;
int curOwnProgress() const;
int maxOwnProgress() const;
Log log() const;

public:
void setState(State newState);
void setDisplay(const QString& display);
void setProgress(int cur, int max);

public:
bool isDefunct() const;

private:
std::shared_ptr<ActivityData> d;
};

}
Loading