Fawkes API  Fawkes Development Version
tf-rest-api.cpp
1 
2 /***************************************************************************
3  * tf-rest-api.cpp - Transforms REST API
4  *
5  * Created: Wed Apr 11 10:11:50 2018
6  * Copyright 2006-2018 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 "tf-rest-api.h"
23 
24 #include <webview/rest_api_manager.h>
25 
26 using namespace fawkes;
27 
28 /** @class TransformsRestApi "skiller-rest-api.h"
29  * REST API backend for the transforms.
30  * @author Tim Niemueller
31  */
32 
33 /** Constructor. */
34 TransformsRestApi::TransformsRestApi() : Thread("TransformsRestApi", Thread::OPMODE_WAITFORWAKEUP)
35 {
36 }
37 
38 /** Destructor. */
40 {
41 }
42 
43 void
45 {
46  rest_api_ = new WebviewRestApi("transforms", logger);
47  rest_api_->add_handler<TransformsGraph>(WebRequest::METHOD_GET,
48  "/graph",
49  std::bind(&TransformsRestApi::cb_get_graph, this));
51 }
52 
53 void
55 {
57  delete rest_api_;
58 }
59 
60 void
62 {
63 }
64 
66 TransformsRestApi::cb_get_graph()
67 {
68  try {
69  TransformsGraph graph;
70  graph.set_kind("TransformsGraph");
73  return graph;
74  } catch (Exception &e) {
75  throw WebviewRestException(WebReply::HTTP_INTERNAL_SERVER_ERROR,
76  "Failed to retrieve transform graph: %s",
77  e.what_no_backtrace());
78  }
79 }
Webview REST API component.
Definition: rest_api.h:220
~TransformsRestApi()
Destructor.
Definition: tf-rest-api.cpp:39
REST processing exception.
Definition: rest_api.h:70
Fawkes library namespace.
virtual void loop()
Code to execute in the thread.
Definition: tf-rest-api.cpp:61
void set_dotgraph(const std::string &dotgraph)
Set dotgraph value.
Thread class encapsulation of pthreads.
Definition: thread.h:45
void unregister_api(WebviewRestApi *api)
Remove a request processor.
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
void register_api(WebviewRestApi *api)
Add a REST API.
virtual void finalize()
Finalize the thread.
Definition: tf-rest-api.cpp:54
virtual void init()
Initialize the thread.
Definition: tf-rest-api.cpp:44
void add_handler(WebRequest::Method method, std::string path, Handler handler)
Add handler function.
Definition: rest_api.cpp:85
Base class for exceptions in Fawkes.
Definition: exception.h:35
void set_kind(const std::string &kind)
Set kind value.
static std::string api_version()
Get version of implemented API.
std::string all_frames_as_dot(bool print_time, fawkes::Time *time=0) const
Get DOT graph of all frames.
virtual const char * what_no_backtrace() const
Get primary string (does not implicitly print the back trace).
Definition: exception.cpp:663
void set_apiVersion(const std::string &apiVersion)
Set apiVersion value.
TransformsRestApi()
Constructor.
Definition: tf-rest-api.cpp:34
WebviewRestApiManager * webview_rest_api_manager
Webview REST API manager.
Definition: webview.h:55
tf::Transformer * tf_listener
This is the transform listener which saves transforms published by other threads in the system.
Definition: tf.h:67
TransformsGraph representation for JSON transfer.