aboutsummaryrefslogtreecommitdiff
path: root/mod/mod-ci.hxx
blob: d7617f474b7aaa41b962c5568c53f1bdf9ee0596 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// file      : mod/mod-ci.hxx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

#ifndef MOD_MOD_CI_HXX
#define MOD_MOD_CI_HXX

#include <web/xhtml/fragment.hxx>

#include <libbrep/types.hxx>
#include <libbrep/utility.hxx>

#include <libbrep/build.hxx>
#include <libbrep/common.hxx> // tenant_service

#include <mod/module.hxx>
#include <mod/module-options.hxx>

#include <mod/ci-common.hxx>
#include <mod/database-module.hxx>

#if defined(BREP_CI_TENANT_SERVICE_UNLOADED) && !defined(BREP_CI_TENANT_SERVICE)
#  error BREP_CI_TENANT_SERVICE must be defined if BREP_CI_TENANT_SERVICE_UNLOADED is defined
#endif

#ifdef BREP_CI_TENANT_SERVICE
#  include <mod/tenant-service.hxx>
#endif

namespace brep
{
  class ci:
#ifndef BREP_CI_TENANT_SERVICE_UNLOADED
            public handler,
#else
            public database_module,
#endif
            private ci_start
#ifdef BREP_CI_TENANT_SERVICE
          , public tenant_service_build_queued,
            public tenant_service_build_building,
            public tenant_service_build_built
#ifdef BREP_CI_TENANT_SERVICE_UNLOADED
          , tenant_service_build_unloaded
#endif
#endif
  {
  public:

#ifdef BREP_CI_TENANT_SERVICE
    explicit
    ci (tenant_service_map&);

    // Create a shallow copy (handling instance) if initialized and a deep
    // copy (context exemplar) otherwise.
    //
    ci (const ci&, tenant_service_map&);
#else
    ci () = default;

    // Create a shallow copy (handling instance) if initialized and a deep
    // copy (context exemplar) otherwise.
    //
    explicit
    ci (const ci&);
#endif

    virtual bool
    handle (request&, response&) override;

    virtual const cli::options&
    cli_options () const override {return options::ci::description ();}

#ifdef BREP_CI_TENANT_SERVICE
    virtual function<optional<string> (const tenant_service&)>
    build_queued (const tenant_service&,
                  const vector<build>&,
                  optional<build_state> initial_state,
                  const build_hints&,
                  const diag_epilogue& log_writer) const noexcept override;

    virtual function<optional<string> (const tenant_service&)>
    build_building (const tenant_service&,
                    const build&,
                    const build_hints&,
                    const diag_epilogue& log_writer) const noexcept override;

    virtual function<optional<string> (const tenant_service&)>
    build_built (const tenant_service&,
                 const build&,
                 const build_hints&,
                 const diag_epilogue& log_writer) const noexcept override;

#ifdef BREP_CI_TENANT_SERVICE_UNLOADED
    virtual function<optional<string> (const tenant_service&)>
    build_unloaded (tenant_service&&,
                    const diag_epilogue& log_writer) const noexcept override;
#endif
#endif

  private:
    virtual void
    init (cli::scanner&) override;

  private:
    shared_ptr<options::ci> options_;
    shared_ptr<web::xhtml::fragment> form_;

#ifdef BREP_CI_TENANT_SERVICE
    tenant_service_map& tenant_service_map_;
#endif
  };

  class ci_cancel: public database_module,
                   private ci_start
  {
  public:
    ci_cancel () = default;

    // Create a shallow copy (handling instance) if initialized and a deep
    // copy (context exemplar) otherwise.
    //
    explicit
    ci_cancel (const ci_cancel&);

    virtual bool
    handle (request&, response&) override;

    virtual const cli::options&
    cli_options () const override {return options::ci_cancel::description ();}

  private:
    virtual void
    init (cli::scanner&) override;

  private:
    shared_ptr<options::ci_cancel> options_;
  };
}

#endif // MOD_MOD_CI_HXX