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
26using 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. */
34TransformsRestApi::TransformsRestApi() : Thread("TransformsRestApi", Thread::OPMODE_WAITFORWAKEUP)
35{
36}
37
38/** Destructor. */
40{
41}
42
43void
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
53void
55{
57 delete rest_api_;
58}
59
60void
62{
63}
64
66TransformsRestApi::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",
78 }
79}
TransformsGraph representation for JSON transfer.
void set_kind(const std::string &kind)
Set kind value.
void set_dotgraph(const std::string &dotgraph)
Set dotgraph value.
void set_apiVersion(const std::string &apiVersion)
Set apiVersion value.
static std::string api_version()
Get version of implemented API.
~TransformsRestApi()
Destructor.
Definition: tf-rest-api.cpp:39
TransformsRestApi()
Constructor.
Definition: tf-rest-api.cpp:34
virtual void init()
Initialize the thread.
Definition: tf-rest-api.cpp:44
virtual void loop()
Code to execute in the thread.
Definition: tf-rest-api.cpp:61
virtual void finalize()
Finalize the thread.
Definition: tf-rest-api.cpp:54
Base class for exceptions in Fawkes.
Definition: exception.h:36
virtual const char * what_no_backtrace() const noexcept
Get primary string (does not implicitly print the back trace).
Definition: exception.cpp:663
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
Thread class encapsulation of pthreads.
Definition: thread.h:46
tf::Transformer * tf_listener
This is the transform listener which saves transforms published by other threads in the system.
Definition: tf.h:67
WebviewRestApiManager * webview_rest_api_manager
Webview REST API manager.
Definition: webview.h:55
void unregister_api(WebviewRestApi *api)
Remove a request processor.
void register_api(WebviewRestApi *api)
Add a REST API.
Webview REST API component.
Definition: rest_api.h:221
void add_handler(WebRequest::Method method, std::string path, Handler handler)
Add handler function.
Definition: rest_api.cpp:85
REST processing exception.
Definition: rest_api.h:71
std::string all_frames_as_dot(bool print_time, fawkes::Time *time=0) const
Get DOT graph of all frames.
Fawkes library namespace.