Fawkes API  Fawkes Development Version
openprs.cpp
1 
2 /***************************************************************************
3  * openprs.cpp - OpenPRS aspect for Fawkes
4  *
5  * Created: Sat Jun 16 14:30:44 2012
6  * Copyright 2006-2012 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <plugins/openprs/aspect/openprs.h>
25 #include <plugins/openprs/utils/openprs_comm.h>
26 #include <core/exception.h>
27 
28 namespace fawkes {
29 #if 0 /* just to make Emacs auto-indent happy */
30 }
31 #endif
32 
33 /** @class OpenPRSAspect <plugins/openprs/aspect/openprs.h>
34  * OpenPRS kernel creation and communication aspect.
35  * This aspect allows access to a specific OpenPRS context through the
36  * OpenPRSKernel communication wrapper. The context is created if it does
37  * not already exist.
38  *
39  * @ingroup Aspects
40  * @author Tim Niemueller
41  */
42 
43 /** @var fawkes:LockPtr<OpenPRSKernel> OpenPRSAspect::openprs
44  * OpenPRS kernel communication wrapper.
45  */
46 
47 /** @var const std::string OpenPRSAspect::openprs_kernel_name
48  * The name of the kernel created for this thread.
49  */
50 
51 /** @var const Mode OpenPRSAspect::openprs_kernel_mode
52  * The kernel mode, can be OPRS or XOPRS (with graphical interface).
53  */
54 
55 /** @var const std::string OpenPRSAspect::openprs_local_name
56  * The local message passer name for communication.
57  */
58 
59 /** Constructor.
60  * @param kernel_name the name of the OpenPRS kernel to connect to.
61  * The context may not exist, yet.
62  * @param mode set to XOPRS to run kernel with graphical user interface,
63  * OPRS to run headless (default)
64  * @param local_name local name to register with to the message passer.
65  * If NULL will be set to "fawkes-|kernel_name|" (where |kernel_name|
66  * will be replaced by the value of @p kernel_name).
67  */
68 OpenPRSAspect::OpenPRSAspect(const char *kernel_name, OpenPRSAspect::Mode mode, const char *local_name)
69  : openprs_kernel_name(kernel_name), openprs_kernel_mode(mode),
70  openprs_local_name(local_name ? local_name : std::string("fawkes-") + kernel_name),
71  openprs_gdb_delay_(false)
72 {
73  add_aspect("OpenPRSAspect");
74  if (openprs_local_name.find_first_of(" \t\n") != std::string::npos) {
75  throw Exception("Local name may not contains spaces");
76  }
77 }
78 
79 
80 /** Virtual empty destructor. */
82 {
83 }
84 
85 
86 /** Add an OpenPRS data path.
87  * The paths are added to the kernel on intialization and are
88  * then searched when including and loading files.
89  * Note that this method may only be called in the constructor,
90  * i.e. before the aspect is initialized.
91  * @param path path to add to search list
92  */
93 void
94 OpenPRSAspect::add_openprs_data_path(const std::string &path)
95 {
96  if (openprs) {
97  throw Exception("OpenPRS kernel has already been intialized");
98  }
99  openprs_data_paths_.push_back(path);
100 }
101 
102 
103 /** Enable/disable GDB delay.
104  * This can be used to order mod_utils to wait for a few seconds to allow
105  * for connecting to the OPRS kernel before it is actually running.
106  * @param enable_gdb_delay true to enable delay, false to disable (default)
107  */
108 void
109 OpenPRSAspect::set_openprs_gdb_delay(const bool enable_gdb_delay)
110 {
111  if (openprs) {
112  throw Exception("OpenPRS kernel has already been intialized");
113  }
114  openprs_gdb_delay_ = enable_gdb_delay;
115 }
116 
117 /** Init OpenPRS aspect.
118  * This sets the OpenPRS kernel communication wrapper.
119  * It is guaranteed that this is called for a OpenPRS Thread before start
120  * is called (when running regularly inside Fawkes).
121  * @param oprs_kernel OpenPRS kernel communication wrapper
122  */
123 void
124 OpenPRSAspect::init_OpenPRSAspect(LockPtr<OpenPRSComm> oprs_comm)
125 {
126  this->openprs = oprs_comm;
127 }
128 
129 /** Finalize OpenPRS aspect.
130  * This clears the OpenPRS environment.
131  */
132 void
133 OpenPRSAspect::finalize_OpenPRSAspect()
134 {
135  openprs.clear();
136 }
137 
138 
139 } // end namespace fawkes
const std::string openprs_local_name
The local message passer name for communication.
Definition: openprs.h:60
Mode
OPRS kernel operation mode.
Definition: openprs.h:45
Fawkes library namespace.
STL namespace.
void add_aspect(const char *name)
Add an aspect to a thread.
Definition: aspect.cpp:52
LockPtr<> is a reference-counting shared lockable smartpointer.
Definition: lockptr.h:57
void set_openprs_gdb_delay(const bool enable_gdb_delay)
Enable/disable GDB delay.
Definition: openprs.cpp:109
Base class for exceptions in Fawkes.
Definition: exception.h:36
void add_openprs_data_path(const std::string &path)
Add an OpenPRS data path.
Definition: openprs.cpp:94
virtual ~OpenPRSAspect()
Virtual empty destructor.
Definition: openprs.cpp:81
LockPtr< OpenPRSComm > openprs
OpenPRS kernel communication wrapper.
Definition: openprs.h:57
OpenPRSAspect(const char *kernel_name, Mode mode=OPRS, const char *local_name=NULL)
Constructor.
Definition: openprs.cpp:68