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
28namespace 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 */
65OpenPRSAspect::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 */
91void
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 */
105void
106OpenPRSAspect::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 */
120void
121OpenPRSAspect::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 */
129void
130OpenPRSAspect::finalize_OpenPRSAspect()
131{
132 openprs.clear();
133}
134
135} // end namespace fawkes
void add_aspect(const char *name)
Add an aspect to a thread.
Definition: aspect.cpp:49
Base class for exceptions in Fawkes.
Definition: exception.h:36
LockPtr<> is a reference-counting shared lockable smartpointer.
Definition: lockptr.h:55
LockPtr< OpenPRSComm > openprs
OpenPRS kernel communication wrapper.
Definition: openprs.h:56
void add_openprs_data_path(const std::string &path)
Add an OpenPRS data path.
Definition: openprs.cpp:92
Mode
OPRS kernel operation mode.
Definition: openprs.h:44
const std::string openprs_local_name
The local message passer name for communication.
Definition: openprs.h:59
void set_openprs_gdb_delay(const bool enable_gdb_delay)
Enable/disable GDB delay.
Definition: openprs.cpp:106
virtual ~OpenPRSAspect()
Virtual empty destructor.
Definition: openprs.cpp:80
OpenPRSAspect(const char *kernel_name, Mode mode=OPRS, const char *local_name=NULL)
Constructor.
Definition: openprs.cpp:65
Fawkes library namespace.