Fawkes API  Fawkes Development Version
skiller_navgraph_feature.cpp
1 /***************************************************************************
2  * skiller_navgraph_thread.cpp - Optional skiller access to navgraph
3  *
4  * Created: Wed Jul 16 13:03:25 2014 (on flight to Joao Pessoa)
5  * Copyright 2012-2014 Tim Niemueller [www.niemueller.de]
6  ****************************************************************************/
7 
8 /* This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Library General Public License for more details.
17  *
18  * Read the full text in the LICENSE.GPL file in the doc directory.
19  */
20 
21 #include "skiller_navgraph_feature.h"
22 
23 #include <navgraph/yaml_navgraph.h>
24 #include <lua/context.h>
25 
26 using namespace fawkes;
27 
28 /** @class SkillerNavGraphFeature "skiller_navgraph_feature.h"
29  * Thread to access the navgraph from skiller.
30  * The thread itself does not perform any actions. But splitting it into its
31  * own thread will allow us to make access to the navgraph optional. So if
32  * the graph is not required the navgraph module does not have to be loaded.
33  * @author Tim Niemueller
34  */
35 
36 /** Constructor. */
38  : Thread("SkillerNavGraphFeature", Thread::OPMODE_WAITFORWAKEUP)
39 {
40 }
41 
42 /** Destructor. */
44 {
45 }
46 
47 void
49 {
50 }
51 
52 void
54 {
55 }
56 
57 void
59 {
60 }
61 
62 
63 void
65 {
66  logger->log_info(name(), "Intializing navgraph for skiller");
67  context->add_package("fawkesnavgraph");
68  context->get_global("features_env_template");
69  context->push_string("navgraph");
70  context->push_usertype(*navgraph, "NavGraph", "fawkes");
71  context->set_table();
72 }
73 
74 void
76 {
77  logger->log_info(name(), "Finalizing navgraph for skiller");
78  context->get_global("features_env_template");
79  context->push_string("navgraph");
80  context->push_nil();
81  context->set_table();
82 }
virtual void loop()
Code to execute in the thread.
virtual void finalize_lua_context(fawkes::LuaContext *context)
Finalize a Lua context.
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
fawkes::LockPtr< NavGraph > navgraph
NavGraph instance shared in framework.
Definition: navgraph.h:46
Fawkes library namespace.
virtual void finalize()
Finalize the thread.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:44
void set_table(int t_index=-3)
Set value of a table.
Definition: context.cpp:1015
void add_package(const char *package)
Add a default package.
Definition: context.cpp:383
void push_nil()
Push nil on top of stack.
Definition: context.cpp:856
virtual ~SkillerNavGraphFeature()
Destructor.
virtual void init_lua_context(fawkes::LuaContext *context)
Initialize a Lua context.
Lua C++ wrapper.
Definition: context.h:47
virtual void init()
Initialize the thread.
const char * name() const
Get name of thread.
Definition: thread.h:95
void push_usertype(void *data, const char *type_name, const char *name_space=0)
Push usertype on top of stack.
Definition: context.cpp:925
void push_string(const char *value)
Push string on top of stack.
Definition: context.cpp:878
void get_global(const char *name)
Get global variable.
Definition: context.cpp:1126