~markwright/scalestack/zeromq

« back to all changes in this revision

Viewing changes to ScaleStack/Kernel.h

  • Committer: Eric Day
  • Date: 2010-02-21 10:36:03 UTC
  • Revision ID: eday@oddments.org-20100221103603-u0agc1fsduqhl728
Initial commit with build system and basic module loading.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Scale Stack
 
3
 *
 
4
 * Copyright (C) 2010 Eric Day (eday@oddments.org)
 
5
 * All rights reserved.
 
6
 *
 
7
 * Use and distribution licensed under the BSD license. See the
 
8
 * COPYING file in the root project directory for full text.
 
9
 */
 
10
 
 
11
/**
 
12
 * @file
 
13
 * @brief Kernel Declarations
 
14
 */
 
15
 
 
16
#ifndef SCALESTACK_KERNEL_H
 
17
#define SCALESTACK_KERNEL_H
 
18
 
 
19
#include <string>
 
20
#include <vector>
 
21
 
 
22
#include <ScaleStack/Common.h>
 
23
 
 
24
namespace ScaleStack
 
25
{
 
26
 
 
27
class Module;
 
28
 
 
29
class SCALESTACK_API Kernel
 
30
{
 
31
public:
 
32
 
 
33
  /**
 
34
   * Constructor to use without argc/argv options.
 
35
   */
 
36
  Kernel(void);
 
37
 
 
38
  /**
 
39
   * Constructor to use when argc and argv from main() should be available
 
40
   * for modules.
 
41
   *
 
42
   * @param[in] argc_arg Argument count.
 
43
   * @param[in] argv_arg Array of argument values.
 
44
   */
 
45
  Kernel(int argc_arg, char** argv_arg);
 
46
 
 
47
  ~Kernel();
 
48
 
 
49
  /**
 
50
   * Get argc and argv that may have been passed in during construction.
 
51
   *
 
52
   * @param[out] argc_arg Argument count.
 
53
   * @param[out] argv_arg Array of argument values.
 
54
   */
 
55
  void getArgcArgv(int* argc_arg, char***argv_arg) const;
 
56
 
 
57
  /**
 
58
   * Add a module to the kernel. If a module by the name already exists,
 
59
   * a ModuleExists exception is throw.
 
60
   *
 
61
   * @param[in] module_name Name of the module to add. This is used in
 
62
   *  constructing the path of the module to load.
 
63
   * @return Reference to module that was added.
 
64
   */
 
65
  Module& addModule(const std::string& module_name);
 
66
 
 
67
  /**
 
68
   * Get a module that has been added to the kernel, or throw ModuleNotFound.
 
69
   *
 
70
   * @param[in] module_name Name of the module to look for. This is used to
 
71
   *  check both the name and canonical name.
 
72
   * @return Reference to module that was found.
 
73
   */
 
74
  Module& getModule(const std::string& module_name) const;
 
75
 
 
76
  /**
 
77
   * Get a module that has been added to the kernel if it exists, and if not,
 
78
   * add the module.
 
79
   *
 
80
   * @param[in] module_name Name of the module to look for or add.
 
81
   * @return Reference to module that was requested.
 
82
   */
 
83
  Module& getOrAddModule(const std::string& module_name);
 
84
 
 
85
  /**
 
86
   * This is the main loop of the kernel and will continue running until
 
87
   * all modules have been removed, a shutdown request is received, or an
 
88
   * uncaught exception is throw.
 
89
   */
 
90
  void run(void);
 
91
 
 
92
private:
 
93
 
 
94
  /**
 
95
   * Don't allow copying or assignment of objects.
 
96
   */
 
97
  Kernel(const Kernel&);
 
98
  Kernel& operator=(const Kernel&);
 
99
 
 
100
  /**
 
101
   * Add a module, used by public functions.
 
102
   *
 
103
   * @param[in] module_name Name of the module to load.
 
104
   * @return Pointer to module that was added.
 
105
   */
 
106
  Module* _addModule(const std::string& module_name);
 
107
 
 
108
  /**
 
109
   * Get a module, used by public functions.
 
110
   *
 
111
   * @param[in] module_name Name of the module to look for. This is used to
 
112
   *  check both the name and canonical name.
 
113
   * @return Pointer to module that was found.
 
114
   */
 
115
  Module* _getModule(const std::string& module_name) const;
 
116
 
 
117
  int argc;
 
118
  char** argv;
 
119
  std::vector<Module*> modules;
 
120
};
 
121
 
 
122
ScaleStackException(ModuleExists);
 
123
ScaleStackException(ModuleNotFound);
 
124
 
 
125
} /* namespace ScaleStack */
 
126
 
 
127
#endif /* SCALESTACK_KERNEL_H */