OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
osvr_dump_tree_json.cpp
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 // Internal Includes
26 #include <osvr/ClientKit/Context.h>
30 
31 // Library/third-party includes
32 #include <boost/program_options.hpp>
33 #include <json/value.h>
34 
35 // Standard includes
36 #include <iostream>
37 #include <thread>
38 #include <chrono>
39 
40 int main(int argc, char *argv[]) {
41  namespace po = boost::program_options;
42  // clang-format off
43  po::options_description desc("Options");
44  desc.add_options()
45  ("help,h", "produce help message")
46  ;
47  // clang-format on
48  po::variables_map vm;
49  bool usage = false;
50  try {
51  po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
52  po::notify(vm);
53  } catch (std::exception &e) {
54  std::cerr << "\nError parsing command line: " << e.what() << "\n\n";
55  usage = true;
56  }
57  if (usage || vm.count("help")) {
58  std::cerr << "\n Dumps the serialized JSON format of the path tree.\n";
59  std::cerr << "Usage: " << argv[0] << "\n\n";
60  return 1;
61  }
62 
63  {
66  osvr::clientkit::ClientContext context("com.osvr.tools.dumptreejson");
67 
68  if (!context.checkStatus()) {
69  std::cerr << "Client context has not yet started up - waiting. "
70  "Make sure the server is running."
71  << std::endl;
72  do {
73  std::this_thread::sleep_for(std::chrono::milliseconds(1));
74  context.update();
75  } while (!context.checkStatus());
76  std::cerr << "OK, client context ready. Proceeding." << std::endl;
77  }
78 
80  auto nodes = osvr::common::pathTreeToJson(context.get()->getPathTree());
81  std::cout << nodes.toStyledString() << std::endl;
82  }
83  return 0;
84 }
Client context object: Create and keep one in your application. Handles lifetime management and provi...
Definition: Context_decl.h:57
bool checkStatus() const
Checks to see if the client context is properly and fully started up.
Definition: Context.h:111
Header including PathTree.h and all additional headers needed to define related types.
Header.
osvr::common::PathTree const & getPathTree() const
Accessor for the path tree.
OSVR_ClientContext get()
Gets the bare OSVR_ClientContext.
Definition: Context.h:109
void update()
Updates the state of the context - call regularly in your mainloop.
Definition: Context.h:54
Json::Value pathTreeToJson(PathTree const &tree, bool keepNulls=false)
Serialize a path tree to a JSON array of objects, one for each node.
int main(int argc, char *argv[])