39 #include <boost/noncopyable.hpp>
40 #include <boost/program_options.hpp>
41 #include <boost/variant.hpp>
49 #include <unordered_set>
54 bool showAliasPriority;
55 bool showDeviceDetails;
56 bool showDeviceDescriptor;
74 : boost::static_visitor<>(), m_opts(opts),
76 m_indentStream(m_maxTypeLen + 2 + 1 + 2, m_os),
77 m_badAliases(begin(badAliases), end(badAliases)) {
91 if (m_opts.showSensors) {
92 outputBasics(node, elt) <<
"\n";
98 outputBasics(node, elt) << std::endl;
102 if (m_badAliases.find(fullPath) != m_badAliases.end()) {
103 m_indentStream <<
"WARNING: this alias does not fully resolve to a "
107 if (m_opts.showAliasSource) {
108 m_indentStream <<
"-> " << elt.
getSource() << std::endl;
110 if (m_opts.showAliasPriority) {
111 m_indentStream <<
"Priority: "
118 outputBasics(node, elt) << std::endl;
119 if (m_opts.showDeviceDetails) {
120 m_indentStream <<
"- corresponds to " << elt.getFullDeviceName()
123 if (m_opts.showDeviceDescriptor) {
124 m_indentStream <<
"- Descriptor: "
125 << elt.getDescriptor().toStyledString() << std::endl;
131 outputBasics(node, elt) << std::endl;
132 if (m_opts.showStringData) {
133 m_indentStream <<
"- Contained value: " << elt.
getString()
140 outputBasics(node, elt) <<
"\n";
146 template <
typename T>
147 std::ostream &outputBasics(
PathNode const &node, T
const &elt) {
158 std::unordered_set<std::string> m_badAliases;
161 int main(
int argc,
char *argv[]) {
163 namespace po = boost::program_options;
165 po::options_description desc(
"Options");
167 (
"help,h",
"produce help message")
168 (
"alias-source", po::value<bool>(&opts.showAliasSource)->default_value(
true),
"Whether or not to show the source associated with each alias")
169 (
"alias-priority", po::value<bool>(&opts.showAliasPriority)->default_value(
false),
"Whether or not to show the priority associated with each alias")
170 (
"device-details", po::value<bool>(&opts.showDeviceDetails)->default_value(
true),
"Whether or not to show the basic details associated with each device")
171 (
"device-descriptors", po::value<bool>(&opts.showDeviceDescriptor)->default_value(
false),
"Whether or not to show the JSON descriptors associated with each device")
172 (
"sensors", po::value<bool>(&opts.showSensors)->default_value(
true),
"Whether or not to show the 'sensor' nodes")
173 (
"string-data", po::value<bool>(&opts.showStringData)->default_value(
true),
"Whether or not to show the data in 'string' nodes")
176 po::variables_map vm;
179 po::store(po::command_line_parser(argc, argv)
186 }
catch (std::exception &e) {
187 std::cerr <<
"\nError parsing command line: " << e.what() <<
"\n\n";
190 if (usage || vm.count(
"help")) {
191 std::cerr <<
"\nTraverses the path tree and outputs it as text for "
192 "human consumption. See\nPathTreeExport for structured "
193 "output for graphical display.\n";
194 std::cerr <<
"Usage: " << argv[0] <<
" [options]\n\n";
195 std::cerr <<
"All options are shown as being --option 1/0 (true/false) "
196 "but may be expressed\nas --show-option or --hide-option "
197 "instead (e.g. --show-alias-priority)\n\n";
198 std::cerr << desc <<
"\n";
203 std::vector<std::string> badAliases;
211 context.
log(OSVR_LOGLEVEL_NOTICE,
212 "Client context has not yet started up - waiting. "
213 "Make sure the server is running.");
215 std::this_thread::sleep_for(std::chrono::milliseconds(1));
218 context.
log(OSVR_LOGLEVEL_NOTICE,
219 "OK, client context ready. Proceeding.");
222 osvr::common::clonePathTree(context.
get()->
getPathTree(), pathTree);
230 osvr::util::log::flush();
238 pathTree.getRoot(), [&printer](
PathNode const &node) {
detail::AliasPriorityWrapper outputPriority(AliasPriority priority)
Helper method to output a priority in a formatted way to a stream.
void operator()(PathNode const &node, elements::StringElement const &elt)
We might print something for a sensor element.
size_t getMaxTypeNameLength()
Gets the length of the longest type name.
void operator()(PathNode const &node, T const &elt)
Catch-all for other element types.
The element type corresponding to a path alias, with a priority level for sorting out whether automat...
Client context object: Create and keep one in your application. Handles lifetime management and provi...
A tree representation, with path/url syntax, of the known OSVR system.
::osvr::util::TreeNode< PathElement > PathNode
The specific tree node type that contains a path element.
void log(OSVR_LogLevel severity, const char *message)
Log a message to the plugin-specific channel.
bool checkStatus() const
Checks to see if the client context is properly and fully started up.
AliasPriority & priority()
Get/set whether this alias was automatically set (and thus subject to being override by explicit rout...
Header including PathTree.h and all additional headers needed to define related types.
TreeNodePrinter(Options opts, std::vector< std::string > const &badAliases)
Constructor.
std::string & getSource()
Get the source of data for this alias.
The element type corresponding to a particular sensor of an interface.
void operator()(PathNode const &node, elements::SensorElement const &elt)
We might print something for a sensor element.
int main(int argc, char *argv[])
void operator()(PathNode const &, elements::NullElement const &)
print nothing for a null element.
The element type corresponding to a device, which implements 0 or more interfaces.
std::string getFullPath(PathNode const &node)
Gets the absolute path for the given node.
void traverseWith(T &node, F &&functor)
A method to handle visiting every node in a tree with a lambda or other by-value function object...
Namespace for the various element types that may constitute a node in the path tree.
The element type corresponding to a string value such as a JSON string.
osvr::common::PathTree const & getPathTree() const
Accessor for the path tree.
OSVR_ClientContext get()
Gets the bare OSVR_ClientContext.
void operator()(PathNode const &node, elements::AliasElement const &elt)
Print aliases.
Visitor::result_type applyPathNodeVisitor(Visitor &v, PathNode &node)
Visit a node's element's contained type, similar to boost::apply_visitor, but passing both the PathNo...
const char * getTypeName(PathNode const &node)
Gets an identifying string for the node value type.
std::vector< std::string > resolveFullTree(PathTree &tree)
Traverse the given path tree, resolving all aliases found to fully populate any generated sensor targ...
A boost::iostreams::filtering_ostream with a constructor that automatically sets it up to indent the ...
void update()
Updates the state of the context - call regularly in your mainloop.
std::string & getString()
Get/set (if non const) the stored string.
void operator()(PathNode const &node, elements::DeviceElement const &elt)
Print Devices.
std::pair< std::string, std::string > convertProgramOptionShowHideIntoTrueFalse(std::string s)
An "additional parser" for Boost.Program_options that will turn any –hide-xyz into –xyz false and â€...
The element type created when requesting a path that isn't yet in the tree.