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 
29 using 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 
45 /** Destructor. */
47 {
48 }
49 
50 
51 void
53 {
54  openprs.lock();
55  openprs->send_message(openprs_kernel_name, "(foo bar)");
56  openprs->transmit_command(openprs_kernel_name, "add (foo2 bar)");
57  openprs.unlock();
58 }
59 
60 void
62 {
63 }
64 
65 
66 void
68 {
69  static int modcount = 0;
70  if (++modcount % 50 == 0) {
71  openprs.lock();
72  openprs->transmit_command(openprs_kernel_name, "show db");
73  openprs.unlock();
74  }
75 }
Fawkes library namespace.
const std::string openprs_kernel_name
The name of the kernel created for this thread.
Definition: openprs.h:58
Thread class encapsulation of pthreads.
Definition: thread.h:42
virtual void finalize()
Finalize the thread.
OpenPRS kernel creation and communication aspect.
Definition: openprs.h:39
Thread aspect to use blocked timing.
virtual ~OpenPRSExampleThread()
Destructor.
LockPtr< OpenPRSComm > openprs
OpenPRS kernel communication wrapper.
Definition: openprs.h:57
virtual void loop()
Code to execute in the thread.
virtual void init()
Initialize the thread.