From ab25857fd626152bc9a2832de82b400c062857e6 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 17 Aug 2007 17:15:04 +0000 Subject: [PATCH] Add class InternalAction for actions that use a thread to do their work Derive Copy and Tar actions from InternalAction Add bootstrap.sh and Readme.txt as tar_files --- Build | 3 +++ source/copy.cpp | 31 +++++++---------------------- source/copy.h | 15 ++++---------- source/internalaction.cpp | 42 +++++++++++++++++++++++++++++++++++++++ source/internalaction.h | 38 +++++++++++++++++++++++++++++++++++ source/tar.cpp | 34 ++++--------------------------- source/tar.h | 14 +++---------- 7 files changed, 101 insertions(+), 76 deletions(-) create mode 100644 source/internalaction.cpp create mode 100644 source/internalaction.h diff --git a/Build b/Build index 279e64c..336bc2a 100644 --- a/Build +++ b/Build @@ -5,6 +5,9 @@ package "builder" version "0.1"; description "Mikkosoft Productions software builder"; + tar_file "bootstrap.sh"; + tar_file "Readme.txt"; + require "mspcore"; require "mspstrings"; require "mspparser"; diff --git a/source/copy.cpp b/source/copy.cpp index 70f0539..eea40fc 100644 --- a/source/copy.cpp +++ b/source/copy.cpp @@ -17,46 +17,29 @@ using namespace std; using namespace Msp; Copy::Copy(Builder &b, const Package &pkg, const Path::Path &s, const Path::Path &d): - Action(b), + InternalAction(b), src(s), - dest(d), - worker(0) + dest(d) { announce(pkg.get_name(), "COPY", dest[-1]); if(builder.get_verbose()>=2) cout< "<get_done()) - { - signal_done.emit(); - worker->join(); - return worker->get_error()?1:0; - } - - return -1; -} -Copy::~Copy() +Copy::Worker::Worker(Copy &c): + copy(c) { - delete worker; + launch(); } void Copy::Worker::main() { Path::mkpath(copy.dest.subpath(0, copy.dest.size()-1), 0755); - + // Remove old file. Not doing this would cause Bad Stuff when installing libraries. if(unlink(copy.dest.str().c_str())<0 && errno!=ENOENT) { diff --git a/source/copy.h b/source/copy.h index a25ea71..0a03ae6 100644 --- a/source/copy.h +++ b/source/copy.h @@ -10,40 +10,33 @@ Distributed under the LGPL #include #include -#include "action.h" +#include "internalaction.h" class Package; /** Copies a file to another place. Used by the Install target. */ -class Copy: public Action +class Copy: public InternalAction { public: Copy(Builder &, const Package &, const Msp::Path::Path &, const Msp::Path::Path &); - int check(); - ~Copy(); private: /** A worker thread that actually does the data transfer. */ - class Worker: public Msp::Thread + class Worker: public InternalAction::Worker { public: - Worker(Copy &i): copy(i), done(false), error(false) { launch(); } - bool get_done() const { return done; } - bool get_error() const { return error; } + Worker(Copy &); private: Copy © - bool done; - bool error; void main(); }; Msp::Path::Path src; Msp::Path::Path dest; - Worker *worker; }; #endif diff --git a/source/internalaction.cpp b/source/internalaction.cpp new file mode 100644 index 0000000..3063aff --- /dev/null +++ b/source/internalaction.cpp @@ -0,0 +1,42 @@ +/* $Id$ + +This file is part of builder +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include "internalaction.h" + +InternalAction::~InternalAction() +{ + delete worker; +} + +int InternalAction::check() +{ + if(!worker) // True for dry run + { + signal_done.emit(); + return 0; + } + + if(worker->get_done()) + { + signal_done.emit(); + worker->join(); + return worker->get_error()?1:0; + } + + return -1; +} + +InternalAction::InternalAction(Builder &b): + Action(b), + worker(0) +{ } + + +InternalAction::Worker::Worker(): + done(false), + error(false) +{ } diff --git a/source/internalaction.h b/source/internalaction.h new file mode 100644 index 0000000..284db03 --- /dev/null +++ b/source/internalaction.h @@ -0,0 +1,38 @@ +/* $Id$ + +This file is part of builder +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#ifndef INTERNALACTION_H_ +#define INTERNALACTION_H_ + +#include +#include "action.h" + +class InternalAction: public Action +{ +public: + virtual ~InternalAction(); + + virtual int check(); +protected: + class Worker: public Msp::Thread + { + public: + bool get_done() const { return done; } + bool get_error() const { return error; } + protected: + bool done; + bool error; + + Worker(); + }; + + Worker *worker; + + InternalAction(Builder &); +}; + +#endif diff --git a/source/tar.cpp b/source/tar.cpp index 0b0c38d..bd29aaf 100644 --- a/source/tar.cpp +++ b/source/tar.cpp @@ -16,47 +16,21 @@ using namespace std; using namespace Msp; Tar::Tar(Builder &b, const TarBall &t): - Action(b), - tarball(t), - worker(0) + InternalAction(b), + tarball(t) { string basename=tarball.get_name().substr(tarball.get_name().rfind('/')+1); announce(tarball.get_package()->get_name(), "TAR ", basename); if(builder.get_verbose()>=2) cout<<"Create "<get_done()) - { - signal_done.emit(); - worker->join(); - return worker->get_error()?1:0; - } - - return -1; -} - Tar::Worker::Worker(Tar &t): - tar(t), - done(false), - error(false) + tar(t) { launch(); } diff --git a/source/tar.h b/source/tar.h index 137a7ee..d81d31b 100644 --- a/source/tar.h +++ b/source/tar.h @@ -9,29 +9,22 @@ Distributed under the LGPL #define TAR_H_ #include -#include "action.h" +#include "internalaction.h" #include "misc.h" class TarBall; -class Tar: public Action +class Tar: public InternalAction { public: Tar(Builder &, const TarBall &); - ~Tar(); - - virtual int check(); private: - class Worker: public Msp::Thread + class Worker: public InternalAction::Worker { public: Worker(Tar &); - bool get_done() const { return done; } - bool get_error() const { return error; } private: Tar &tar; - bool done; - bool error; void main(); void store_number(char *, unsigned, unsigned); @@ -39,7 +32,6 @@ private: const TarBall &tarball; StringList files; - Worker *worker; }; #endif -- 2.45.2