Apache Mesos
test_module.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __TEST_MODULE_HPP__
18 #define __TEST_MODULE_HPP__
19 
20 #include <mesos/mesos.hpp>
21 #include <mesos/module.hpp>
22 
23 #include <stout/nothing.hpp>
24 #include <stout/try.hpp>
25 
26 // Each module "kind" has a base class associated with it that is
27 // inherited by the module instances. Mesos core uses the base
28 // class interface to bind with the module instances.
29 // TestModule is a base class for the "TestModule" kind.
31 {
32 public:
34 
35  // Mesos core will use the base class pointer to delete the module
36  // instance (which is a derived object). The virtual destructor
37  // here ensures that the derived destructor is called for any
38  // cleanup that may be required for the derived object.
39  virtual ~TestModule() {}
40 
41  virtual Try<Nothing> initialize(const mesos::Parameters& parameters) = 0;
42 
43  virtual int foo(char a, long b) = 0;
44 
45  virtual int bar(float a, double b) = 0;
46 
47  virtual int baz(int a, int b) = 0;
48 
49  virtual mesos::Parameters parameters() const = 0;
50 };
51 
52 
53 namespace mesos {
54 namespace modules {
55 
56 template <>
57 inline const char* kind<TestModule>()
58 {
59  return "TestModule";
60 }
61 
62 
63 template <>
65 {
67  const char* _moduleApiVersion,
68  const char* _mesosVersion,
69  const char* _authorName,
70  const char* _authorEmail,
71  const char* _description,
72  bool (*_compatible)(),
73  TestModule* (*_create)(const Parameters& parameters))
74  : ModuleBase(
75  _moduleApiVersion,
76  _mesosVersion,
77  mesos::modules::kind<TestModule>(),
78  _authorName,
79  _authorEmail,
80  _description,
81  _compatible),
82  create(_create) {}
83 
84  TestModule* (*create)(const Parameters& parameters);
85 };
86 
87 } // namespace modules {
88 } // namespace mesos {
89 
90 #endif // __TEST_MODULE_HPP__
Module(const char *_moduleApiVersion, const char *_mesosVersion, const char *_authorName, const char *_authorEmail, const char *_description, bool(*_compatible)(), TestModule *(*_create)(const Parameters &parameters))
Definition: test_module.hpp:66
Definition: check.hpp:33
Definition: module.hpp:56
const char * kind< TestModule >()
Definition: test_module.hpp:57
virtual int foo(char a, long b)=0
Definition: test_module.hpp:30
virtual Try< Nothing > initialize(const mesos::Parameters &parameters)=0
const char * kind()
TestModule()
Definition: test_module.hpp:33
Definition: agent.hpp:25
virtual int baz(int a, int b)=0
virtual ~TestModule()
Definition: test_module.hpp:39
Try< Nothing > create(const std::string &hierarchy, const std::string &cgroup, bool recursive=false)
virtual mesos::Parameters parameters() const =0
virtual int bar(float a, double b)=0
Definition: module.hpp:97