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 <core/exception.h>
25 #include <plugins/openprs/aspect/openprs.h>
26 #include <plugins/openprs/utils/openprs_comm.h>
27 
28 namespace fawkes {
29 
30 /** @class OpenPRSAspect <plugins/openprs/aspect/openprs.h>
31  * OpenPRS kernel creation and communication aspect.
32  * This aspect allows access to a specific OpenPRS context through the
33  * OpenPRSKernel communication wrapper. The context is created if it does
34  * not already exist.
35  *
36  * @ingroup Aspects
37  * @author Tim Niemueller
38  */
39 
40 /** @var fawkes:LockPtr<OpenPRSKernel> OpenPRSAspect::openprs
41  * OpenPRS kernel communication wrapper.
42  */
43 
44 /** @var const std::string OpenPRSAspect::openprs_kernel_name
45  * The name of the kernel created for this thread.
46  */
47 
48 /** @var const Mode OpenPRSAspect::openprs_kernel_mode
49  * The kernel mode, can be OPRS or XOPRS (with graphical interface).
50  */
51 
52 /** @var const std::string OpenPRSAspect::openprs_local_name
53  * The local message passer name for communication.
54  */
55 
56 /** Constructor.
57  * @param kernel_name the name of the OpenPRS kernel to connect to.
58  * The context may not exist, yet.
59  * @param mode set to XOPRS to run kernel with graphical user interface,
60  * OPRS to run headless (default)
61  * @param local_name local name to register with to the message passer.
62  * If NULL will be set to "fawkes-|kernel_name|" (where |kernel_name|
63  * will be replaced by the value of @p kernel_name).
64  */
65 OpenPRSAspect::OpenPRSAspect(const char * kernel_name,
67  const char * local_name)
68 : openprs_kernel_name(kernel_name),
69  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 /** Virtual empty destructor. */
81 {
82 }
83 
84 /** Add an OpenPRS data path.
85  * The paths are added to the kernel on intialization and are
86  * then searched when including and loading files.
87  * Note that this method may only be called in the constructor,
88  * i.e. before the aspect is initialized.
89  * @param path path to add to search list
90  */
91 void
92 OpenPRSAspect::add_openprs_data_path(const std::string &path)
93 {
94  if (openprs) {
95  throw Exception("OpenPRS kernel has already been intialized");
96  }
97  openprs_data_paths_.push_back(path);
98 }
99 
100 /** Enable/disable GDB delay.
101  * This can be used to order mod_utils to wait for a few seconds to allow
102  * for connecting to the OPRS kernel before it is actually running.
103  * @param enable_gdb_delay true to enable delay, false to disable (default)
104  */
105 void
106 OpenPRSAspect::set_openprs_gdb_delay(const bool enable_gdb_delay)
107 {
108  if (openprs) {
109  throw Exception("OpenPRS kernel has already been intialized");
110  }
111  openprs_gdb_delay_ = enable_gdb_delay;
112 }
113 
114 /** Init OpenPRS aspect.
115  * This sets the OpenPRS kernel communication wrapper.
116  * It is guaranteed that this is called for a OpenPRS Thread before start
117  * is called (when running regularly inside Fawkes).
118  * @param oprs_kernel OpenPRS kernel communication wrapper
119  */
120 void
121 OpenPRSAspect::init_OpenPRSAspect(LockPtr<OpenPRSComm> oprs_comm)
122 {
123  this->openprs = oprs_comm;
124 }
125 
126 /** Finalize OpenPRS aspect.
127  * This clears the OpenPRS environment.
128  */
129 void
130 OpenPRSAspect::finalize_OpenPRSAspect()
131 {
132  openprs.clear();
133 }
134 
135 } // end namespace fawkes
fawkes::OpenPRSAspect::set_openprs_gdb_delay
void set_openprs_gdb_delay(const bool enable_gdb_delay)
Enable/disable GDB delay.
Definition: openprs.cpp:110
fawkes::OpenPRSAspect::openprs
LockPtr< OpenPRSComm > openprs
Definition: openprs.h:60
fawkes::OpenPRSAspect::~OpenPRSAspect
virtual ~OpenPRSAspect()
Virtual empty destructor.
Definition: openprs.cpp:84
fawkes
fawkes::OpenPRSAspect::add_openprs_data_path
void add_openprs_data_path(const std::string &path)
Add an OpenPRS data path.
Definition: openprs.cpp:96
fawkes::OpenPRSAspect::Mode
Mode
OPRS kernel operation mode.
Definition: openprs.h:48
fawkes::OpenPRSAspect::OpenPRSAspect
OpenPRSAspect(const char *kernel_name, Mode mode=OPRS, const char *local_name=NULL)
Constructor.
Definition: openprs.cpp:69
fawkes::Exception
Definition: exception.h:39