Back to index

unity  6.0.0
Namespaces | Classes | Functions | Variables
unity::debug Namespace Reference

Namespaces

namespace  local

Classes

class  DebugDBusInterface
class  XPathQueryPart
class  Introspectable
class  ResultWrapper
 Wrap a result object from UnityCore and present it's properties to the introspectable tree. More...

Functions

GVariant * GetState (std::string const &query)
void StartLogToFile (std::string const &file_path)
void ResetLogging ()
void SetLogSeverity (std::string const &log_component, std::string const &severity)
void LogMessage (std::string const &severity, std::string const &message)
std::list< Introspectable * > GetIntrospectableNodesFromQuery (std::string const &query, Introspectable *tree_root)

Variables

static Introspectable_parent_introspectable

Function Documentation

std::list< Introspectable * > unity::debug::GetIntrospectableNodesFromQuery ( std::string const &  query,
Introspectable *  tree_root 
)

Definition at line 280 of file DebugDBusInterface.cpp.

{
  std::list<Introspectable*> start_points;
  std::string sanitised_query;
  // Allow user to be lazy when specifying root node.
  if (query == "" || query == "/")
  {
    sanitised_query = "/" + tree_root->GetName();
  }
  else
  {
    sanitised_query = query;
  }
  // split query into parts
  std::list<XPathQueryPart> query_parts;

  {
    std::list<std::string> query_strings;
    boost::algorithm::split(query_strings, sanitised_query, boost::algorithm::is_any_of("/"));
    // Boost's split() implementation does not match it's documentation! According to the
    // docs, it's not supposed to add empty strings, but it does, which is a PITA. This
    // next line removes them:
    query_strings.erase( std::remove_if( query_strings.begin(),
                                        query_strings.end(),
                                        boost::bind( &std::string::empty, _1 ) ),
                      query_strings.end());
    foreach(std::string part, query_strings)
    {
      query_parts.push_back(XPathQueryPart(part));
    }
  }

  // absolute or relative query string?
  if (sanitised_query.at(0) == '/' && sanitised_query.at(1) != '/')
  {
    // absolute query - start point is tree root node.
    if (query_parts.front().Matches(tree_root))
    {
      start_points.push_back(tree_root);
    }
  }
  else
  {
    // relative - need to do a depth first tree search for all nodes that match the
    // first node in the query.

    // warn about malformed queries (all queries must start with '/')
    if (sanitised_query.at(0) != '/')
    {
      LOG_WARNING(logger) << "Malformed relative introspection query: '" << query << "'.";
    }

    // non-recursive BFS traversal to find starting points:
    std::queue<Introspectable*> queue;
    queue.push(tree_root);
    while (!queue.empty())
    {
      Introspectable *node = queue.front();
      queue.pop();
      if (query_parts.front().Matches(node))
      {
        // found one. We keep going deeper, as there may be another node beneath this one
        // with the same node name.
        start_points.push_back(node);
      }
      // Add all children of current node to queue.
      foreach(Introspectable* child, node->GetIntrospectableChildren())
      {
        queue.push(child);
      }
    }
  }

  // now we have the tree start points, process them:
  query_parts.pop_front();
  typedef std::pair<Introspectable*, std::list<XPathQueryPart>::iterator> node_match_pair;

  std::queue<node_match_pair> traverse_queue;
  foreach(Introspectable *node, start_points)
  {
    traverse_queue.push(node_match_pair(node, query_parts.begin()));
  }
  start_points.clear();

  while (!traverse_queue.empty())
  {
    node_match_pair p = traverse_queue.front();
    traverse_queue.pop();

    Introspectable *node = p.first;
    auto query_it = p.second;

    if (query_it == query_parts.end())
    {
      // found a match:
      start_points.push_back(node);
    }
    else
    {
      // push all children of current node to start of queue, advance search iterator, and loop again.
      foreach (Introspectable *child, node->GetIntrospectableChildren())
      {
        if (query_it->Matches(child))
        {
          auto it_copy(query_it);
          ++it_copy;
          traverse_queue.push(node_match_pair(child, it_copy));
        }
      }
    }
  }
  return start_points;
}

Here is the call graph for this function:

Here is the caller graph for this function:

GVariant * unity::debug::GetState ( std::string const &  query)

Definition at line 225 of file DebugDBusInterface.cpp.

{
  // process the XPath query:
  std::list<Introspectable*> parts = GetIntrospectableNodesFromQuery(query, _parent_introspectable);
  GVariantBuilder  builder;
  g_variant_builder_init(&builder, G_VARIANT_TYPE("a(sv)"));
  if (parts.empty())
  {
    LOG_WARNING(logger) << "Query '" << query << "' Did not match anything.";
  }
  for (Introspectable *node : parts)
  {
    g_variant_builder_add(&builder, "(sv)", node->GetName().c_str(), node->Introspect());
  }

  return g_variant_new("(a(sv))", &builder);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::debug::LogMessage ( std::string const &  severity,
std::string const &  message 
)

Definition at line 265 of file DebugDBusInterface.cpp.

{
  nux::logging::Level level = nux::logging::get_logging_level(severity);
  if (logger.GetEffectiveLogLevel() <= level)
  {
   nux::logging::LogStream(level, logger.module(), __FILE__, __LINE__).stream()
      << message;
  }
}

Here is the caller graph for this function:

Definition at line 251 of file DebugDBusInterface.cpp.

{
  if (local::output_file.is_open())
    local::output_file.close();
  nux::logging::Writer::Instance().SetOutputStream(std::cout);
  nux::logging::reset_logging();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::debug::SetLogSeverity ( std::string const &  log_component,
std::string const &  severity 
)

Definition at line 259 of file DebugDBusInterface.cpp.

{
  nux::logging::Logger(log_component).SetLogLevel(nux::logging::get_logging_level(severity));
}

Here is the caller graph for this function:

void unity::debug::StartLogToFile ( std::string const &  file_path)

Definition at line 243 of file DebugDBusInterface.cpp.

{
  if (local::output_file.is_open())
    local::output_file.close();
  local::output_file.open(file_path);
  nux::logging::Writer::Instance().SetOutputStream(local::output_file);
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 101 of file DebugDBusInterface.cpp.