LibPkg
trigger.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 // Copyright � 2003-2005 Graham Shaw.
3 // Copyright � 2015 Alan Buckley.
4 // Distribution and use are subject to the GNU Lesser General Public License,
5 // a copy of which may be found in the file !LibPkg.Copyright.
6 //
7 #ifndef LIBPKG_TRIGGER
8 #define LIBPKG_TRIGGER
9 
10 #include <string>
11 #include <vector>
12 
13 namespace pkg
14 {
15  class pkgbase;
16  class trigger_run;
17  class log;
18 
22  class trigger
23  {
24  public:
27  private:
28  pkgbase &_pb;
29  std::string _pkgname;
30  action_type _action;
31  std::string _old_version;
32  std::string _new_version;
33  trigger_run *_runner;
34  state_type _state;
35  std::string _message;
36  std::vector<std::string> _paths;
37  log *_log;
38 
39  public:
40  trigger(pkgbase &pb, const std::string &pkgname, trigger::action_type action, const std::string &old_version, const std::string &new_version, trigger_run *runner);
41 
42  void log_to(log *log) {_log = log;}
43  void run();
44 
46  bool finished() const { return (_state == state_success) || (_state == state_error); }
47 
48  const std::string &pkgname() const {return _pkgname;}
49  action_type action() const {return _action;}
50  state_type state() const {return _state;}
51  const std::string &message() const {return _message;}
52 
53  void trigger_start_failed(const std::string &reason);
54  void trigger_log(const std::string &text);
55  void trigger_finished();
56  private:
57  std::string trigger_path();
58  void delete_env_vars();
59  };
60 
67  {
68  public:
69  virtual ~trigger_run() {}
84  virtual void run(const std::string &file_name, pkg::trigger *trigger) = 0;
85  };
86 }
87 
88 #endif
state_type
Definition: trigger.h:26
void run()
Run the trigger.
Definition: trigger.cc:80
Definition: trigger.h:25
const std::string & message() const
Definition: trigger.h:51
void log_to(log *log)
Definition: trigger.h:42
bool finished() const
Check if the triggers has finished running.
Definition: trigger.h:46
Definition: trigger.h:26
Definition: trigger.h:26
void trigger_finished()
Callback from trigger_run when the trigger finished.
Definition: trigger.cc:216
Definition: trigger.h:25
Definition: trigger.h:25
action_type action() const
Definition: trigger.h:49
void trigger_log(const std::string &text)
Log any output from the trigger.
Definition: trigger.cc:176
const std::string & pkgname() const
Definition: trigger.h:48
class to represent a trigger action from a script
Definition: trigger.h:22
state_type state() const
Definition: trigger.h:50
Definition: trigger.h:26
Class to log actions that occur in LibPkg.
Definition: log.h:206
Interface to execute a trigger.
Definition: trigger.h:66
trigger(pkgbase &pb, const std::string &pkgname, trigger::action_type action, const std::string &old_version, const std::string &new_version, trigger_run *runner)
Construct a new trigger.
Definition: trigger.cc:24
Definition: trigger.h:25
A class for representing the collection of package database tables.
Definition: pkgbase.h:22
action_type
Definition: trigger.h:25
void trigger_start_failed(const std::string &reason)
Callback from trigger_run if the trigger could not be started.
Definition: trigger.cc:159
Definition: trigger.h:25
virtual void run(const std::string &file_name, pkg::trigger *trigger)=0
Run the given trigger during install/remove/upgrade.
virtual ~trigger_run()
Definition: trigger.h:69
Definition: trigger.h:26
Definition: trigger.h:25

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)