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 /** Destructor. */
46 {
47 }
48 
49 void
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 
58 void
60 {
61 }
62 
63 void
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 }
OpenPRSExampleThread::init
virtual void init()
Initialize the thread.
Definition: openprs_example_thread.cpp:49
fawkes::OpenPRSAspect
Definition: openprs.h:42
OpenPRSExampleThread::~OpenPRSExampleThread
virtual ~OpenPRSExampleThread()
Destructor.
Definition: openprs_example_thread.cpp:44
fawkes::BlockedTimingAspect
Definition: blocked_timing.h:54
OpenPRSExampleThread::loop
virtual void loop()
Code to execute in the thread.
Definition: openprs_example_thread.cpp:63
fawkes::OpenPRSAspect::openprs
LockPtr< OpenPRSComm > openprs
Definition: openprs.h:60
fawkes::OpenPRSAspect::openprs_kernel_name
const std::string openprs_kernel_name
Definition: openprs.h:61
OpenPRSExampleThread::OpenPRSExampleThread
OpenPRSExampleThread()
Constructor.
Definition: openprs_example_thread.cpp:36
fawkes
OpenPRSExampleThread::finalize
virtual void finalize()
Finalize the thread.
Definition: openprs_example_thread.cpp:58
fawkes::Thread
Definition: thread.h:44