]> git.tdb.fi Git - builder.git/commitdiff
Add class InternalAction for actions that use a thread to do their work
authorMikko Rasa <tdb@tdb.fi>
Fri, 17 Aug 2007 17:15:04 +0000 (17:15 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 17 Aug 2007 17:15:04 +0000 (17:15 +0000)
Derive Copy and Tar actions from InternalAction
Add bootstrap.sh and Readme.txt as tar_files

Build
source/copy.cpp
source/copy.h
source/internalaction.cpp [new file with mode: 0644]
source/internalaction.h [new file with mode: 0644]
source/tar.cpp
source/tar.h

diff --git a/Build b/Build
index 279e64cf0c2855f1a2b5bf747e14a8041fc51d8b..336bc2a37c55cdf4c2d761dbe093f5818447100c 100644 (file)
--- 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";
index 70f05398fbac5ae5dc885d7c91c8c33eb95da4ae..eea40fcdae6eda6f63dc30f09988736fa88a7fbc 100644 (file)
@@ -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<<s<<" -> "<<d<<'\n';
-       
+
        if(!builder.get_dry_run())
                worker=new Worker(*this);
 }
 
-int Copy::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;
-}
 
-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)
        {
index a25ea7105cdbfa6dfd7c14305eb1f9cd90f6c8b9..0a03ae6d2c12edb081b338b8820ae97623c81486 100644 (file)
@@ -10,40 +10,33 @@ Distributed under the LGPL
 
 #include <msp/core/thread.h>
 #include <msp/path/path.h>
-#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 &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 (file)
index 0000000..3063aff
--- /dev/null
@@ -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 (file)
index 0000000..284db03
--- /dev/null
@@ -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 <msp/core/thread.h>
+#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
index 0b0c38df775696fcf1e98d8333a3357df68af305..bd29aafc56543547a0f91c5b360398aae2546e48 100644 (file)
@@ -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 "<<basename<<'\n';
-       
+
        if(!builder.get_dry_run())
                worker=new Worker(*this);
 }
 
-Tar::~Tar()
-{
-       delete worker;
-}
-
-int Tar::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;
-}
-
 
 Tar::Worker::Worker(Tar &t):
-       tar(t),
-       done(false),
-       error(false)
+       tar(t)
 {
        launch();
 }
index 137a7ee00969af8bcaa78307e614ee511fa0b63b..d81d31bae195beb4ffd925a119cb14862a236a41 100644 (file)
@@ -9,29 +9,22 @@ Distributed under the LGPL
 #define TAR_H_
 
 #include <msp/core/thread.h>
-#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