Fawkes API  Fawkes Development Version
finalize_nettler_thread.cpp
1 
2 /***************************************************************************
3  * finalize_nettler_thread.cpp - Fawkes Example Plugin Finalize Nettler Thread
4  *
5  * Created: Thu May 24 00:35:06 2007
6  * Copyright 2006-2008 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.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include <plugins/examples/basics/finalize_nettler_thread.h>
24 
25 #include <unistd.h>
26 
27 using namespace fawkes;
28 
29 /** @class ExampleFinalizeNettlerThread plugins/examples/basics/finalize_nettler_thread.h
30  * Thread of example plugin.
31  * This thread does nothing but nagging once on finalize. On the first call to
32  * prepare finalize it returns false that it cannot be finalized,
33  * on the second time it allows finalization.
34  * @author Tim Niemueller
35  */
36 
37 /** Constructor.
38  * @param name thread name
39  */
41  : Thread(name, Thread::OPMODE_WAITFORWAKEUP)
42 {
43  nagged = false;
44 }
45 
46 
47 /** Destructor. */
49 {
50 }
51 
52 
53 /** Thread loop.
54  * If num iterations module modc is 0 print out messaege, otherwise do nothing.
55  */
56 void
58 {
59 }
60 
61 
62 void
64 {
65  logger->log_info("ExampleFinalizeNettlerThread", "init() called");
66 }
67 
68 
69 void
71 {
72  logger->log_info("ExampleFinalizeNettlerThread", "finalize() called");
73 }
74 
75 
76 bool
78 {
79  if ( nagged ) {
80  logger->log_warn("ExampleFinalizeNettlerThread", "Allowing Finalization");
81  return true;
82  } else {
83  logger->log_warn("ExampleFinalizeNettlerThread", "NOT allowing Finalization");
84  nagged = true;
85  return false;
86  }
87 }
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
Fawkes library namespace.
virtual bool prepare_finalize_user()
Prepare finalization user implementation.
Thread class encapsulation of pthreads.
Definition: thread.h:42
virtual ~ExampleFinalizeNettlerThread()
Destructor.
virtual void loop()
Thread loop.
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:44
virtual void finalize()
Finalize the thread.
ExampleFinalizeNettlerThread(const char *name)
Constructor.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
virtual void init()
Initialize the thread.