LibPkg
trigger.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 //
3 // Copyright 2003-2020 Graham Shaw
4 // Copyright 2015-2020 Alan Buckley
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 
18 #ifndef LIBPKG_TRIGGER
19 #define LIBPKG_TRIGGER
20 
21 #include <string>
22 #include <vector>
23 
24 namespace pkg
25 {
26  class pkgbase;
27  class trigger_run;
28  class log;
29 
33  class trigger
34  {
35  public:
38  private:
39  pkgbase &_pb;
40  std::string _pkgname;
41  action_type _action;
42  std::string _old_version;
43  std::string _new_version;
44  trigger_run *_runner;
45  state_type _state;
46  std::string _message;
47  std::vector<std::string> _paths;
48  log *_log;
49 
50  public:
51  trigger(pkgbase &pb, const std::string &pkgname, trigger::action_type action, const std::string &old_version, const std::string &new_version, trigger_run *runner);
52 
53  void log_to(log *log) {_log = log;}
54  void run();
55 
57  bool finished() const { return (_state == state_success) || (_state == state_error); }
58 
59  const std::string &pkgname() const {return _pkgname;}
60  action_type action() const {return _action;}
61  state_type state() const {return _state;}
62  const std::string &message() const {return _message;}
63 
64  void trigger_start_failed(const std::string &reason);
65  void trigger_log(const std::string &text);
66  void trigger_finished();
67  private:
68  std::string trigger_path();
69  void delete_env_vars();
70  };
71 
78  {
79  public:
80  virtual ~trigger_run() {}
95  virtual void run(const std::string &file_name, pkg::trigger *trigger) = 0;
96  };
97 }
98 
99 #endif
state_type
Definition: trigger.h:37
void run()
Run the trigger.
Definition: trigger.cc:96
const std::string & message() const
Definition: trigger.h:62
Definition: trigger.h:36
void log_to(log *log)
Definition: trigger.h:53
Definition: trigger.h:37
Definition: trigger.h:37
The namespace used to hold the package management library.
Definition: auto_dir.cc:23
void trigger_finished()
Callback from trigger_run when the trigger finished.
Definition: trigger.cc:232
bool finished() const
Check if the triggers has finished running.
Definition: trigger.h:57
Definition: trigger.h:36
Definition: trigger.h:36
void trigger_log(const std::string &text)
Log any output from the trigger.
Definition: trigger.cc:192
class to represent a trigger action from a script
Definition: trigger.h:33
action_type action() const
Definition: trigger.h:60
Definition: trigger.h:37
Class to log actions that occur in LibPkg.
Definition: log.h:226
Interface to execute a trigger.
Definition: trigger.h:77
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:40
Definition: trigger.h:36
A class for representing the collection of package database tables.
Definition: pkgbase.h:35
state_type state() const
Definition: trigger.h:61
action_type
Definition: trigger.h:36
const std::string & pkgname() const
Definition: trigger.h:59
void trigger_start_failed(const std::string &reason)
Callback from trigger_run if the trigger could not be started.
Definition: trigger.cc:175
Definition: trigger.h:36
virtual ~trigger_run()
Definition: trigger.h:80
Definition: trigger.h:37
Definition: trigger.h:36

Reference Manual LibPkg Version 0.9.0 (4 Sep 2020)