Fawkes API Fawkes Development Version
openprs_example_thread.cpp
1
2/***************************************************************************
3 * openprs_example_thread.cpp - OpenPRS example thread
4 *
5 * Created: Tue Aug 19 11:51:33 2014
6 * Copyright 2014 Tim Niemueller [www.niemueller.de]
7 ****************************************************************************/
8
9/* This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Library General Public License for more details.
18 *
19 * Read the full text in the LICENSE.GPL file in the doc directory.
20 */
21
22#include "openprs_example_thread.h"
23
24#include <logging/logger.h>
25#include <plugins/openprs/utils/openprs_comm.h>
26
27#include <unistd.h>
28
29using namespace fawkes;
30
31/** @class OpenPRSExampleThread "openprs_example_thread.h"
32 * OpenPRS example thread.
33 * @author Tim Niemueller
34 */
35
36/** Constructor. */
38: Thread("OpenPRSExampleThread", Thread::OPMODE_WAITFORWAKEUP),
39 BlockedTimingAspect(BlockedTimingAspect::WAKEUP_HOOK_THINK),
40 OpenPRSAspect("openprs-example", OpenPRSAspect::OPRS)
41{
42}
43
44/** Destructor. */
46{
47}
48
49void
51{
52 openprs.lock();
53 openprs->send_message(openprs_kernel_name, "(foo bar)");
54 openprs->transmit_command(openprs_kernel_name, "add (foo2 bar)");
55 openprs.unlock();
56}
57
58void
60{
61}
62
63void
65{
66 static int modcount = 0;
67 if (++modcount % 50 == 0) {
68 openprs.lock();
69 openprs->transmit_command(openprs_kernel_name, "show db");
70 openprs.unlock();
71 }
72}
virtual void init()
Initialize the thread.
virtual void loop()
Code to execute in the thread.
virtual void finalize()
Finalize the thread.
virtual ~OpenPRSExampleThread()
Destructor.
Thread aspect to use blocked timing.
OpenPRS kernel creation and communication aspect.
Definition: openprs.h:39
LockPtr< OpenPRSComm > openprs
OpenPRS kernel communication wrapper.
Definition: openprs.h:56
const std::string openprs_kernel_name
The name of the kernel created for this thread.
Definition: openprs.h:57
Thread class encapsulation of pthreads.
Definition: thread.h:46
Fawkes library namespace.