예제 #1
0
PendingCall StubBase::send_request(const char* method_name, std::function<void(DBusMessageIter&)>&& f, bool is_oneway)
{
    message_ptr_t msg = make_message(dbus_message_new_method_call(busname().c_str(), objectpath(), iface(), method_name));
    DBusPendingCall* pending = nullptr;

    DBusMessageIter iter;
    dbus_message_iter_init_append(msg.get(), &iter);
    
    f(iter);

    if (!is_oneway)
    {
        int timeout = disp().request_timeout();

        if (detail::request_specific_timeout.count() > 0)
            timeout = detail::request_specific_timeout.count();

        dbus_connection_send_with_reply(disp().conn_, msg.get(), &pending, timeout);
    }
    else
    {
       // otherwise server would stop reading requests after a while
       dbus_message_set_no_reply(msg.get(), TRUE);

       dbus_connection_send(disp().conn_, msg.get(), nullptr);
       dbus_connection_flush(disp().conn_);
    }

    detail::request_specific_timeout = std::chrono::milliseconds(0);

    return PendingCall(dbus_message_get_serial(msg.get()), pending);
}
예제 #2
0
void StubBase::set_property(const char* name, std::function<void(DBusMessageIter&)>&& f)
{
    message_ptr_t msg = make_message(dbus_message_new_method_call(busname().c_str(), objectpath(), "org.freedesktop.DBus.Properties", "Set"));

    DBusMessageIter iter;
    dbus_message_iter_init_append(msg.get(), &iter);
   
    encode(iter, iface(), name);

    f(iter);   // and now serialize the variant

     DBusError err;
     dbus_error_init(&err);

     DBusMessage* reply = dbus_connection_send_with_reply_and_block(disp().conn_, msg.get(), DBUS_TIMEOUT_USE_DEFAULT, &err);

     // drop original message
     msg.reset(reply);

     // check for reponse
     if (dbus_error_is_set(&err))
     {
        // TODO make static function to throw from DBusError
        Error ex(err.name, err.message);

        dbus_error_free(&err);
        throw ex;
    }
}
예제 #3
0
PendingCall StubBase::get_property_async(const char* name)
{
   message_ptr_t msg = make_message(dbus_message_new_method_call(busname().c_str(), objectpath(), "org.freedesktop.DBus.Properties", "Get"));
   DBusPendingCall* pending = nullptr;

   DBusMessageIter iter;
   dbus_message_iter_init_append(msg.get(), &iter);
    
   encode(iter, iface(), name);

   dbus_connection_send_with_reply(conn(), msg.get(), &pending, DBUS_TIMEOUT_USE_DEFAULT);

   return PendingCall(dbus_message_get_serial(msg.get()), pending);
}
예제 #4
0
PendingCall StubBase::set_property_async(const char* name, std::function<void(DBusMessageIter&)>&& f)
{
    message_ptr_t msg = make_message(dbus_message_new_method_call(busname().c_str(), objectpath(), "org.freedesktop.DBus.Properties", "Set"));

    DBusMessageIter iter;
    dbus_message_iter_init_append(msg.get(), &iter);
    
    encode(iter, iface(), name);
    f(iter);   // and now serialize the variant

    DBusPendingCall* pending = nullptr;

    dbus_connection_send_with_reply(disp().conn_, msg.get(), &pending, DBUS_TIMEOUT_USE_DEFAULT);

    return PendingCall(dbus_message_get_serial(msg.get()), pending);
}
예제 #5
0
message_ptr_t StubBase::send_request_and_block(const char* method_name, std::function<void(DBusMessageIter&)>&& f, bool is_oneway)
{
    message_ptr_t msg = make_message(dbus_message_new_method_call(busname().c_str(), objectpath(), iface(), method_name));
    DBusPendingCall* pending = nullptr;
    message_ptr_t rc(nullptr, &dbus_message_unref);

    DBusMessageIter iter;
    dbus_message_iter_init_append(msg.get(), &iter);
    
    f(iter);

    if (!is_oneway)
    {
        int timeout = disp().request_timeout();

        if (detail::request_specific_timeout.count() > 0)
            timeout = detail::request_specific_timeout.count();

        dbus_connection_send_with_reply(disp().conn_, msg.get(), &pending, timeout);

        detail::request_specific_timeout = std::chrono::milliseconds(0);

        dbus_pending_call_block(pending);

        rc = make_message(dbus_pending_call_steal_reply(pending));
        dbus_pending_call_unref(pending);

        CallState cs(*rc);

        if (!cs)
           cs.throw_exception();
    }
    else
    {
       // otherwise server would stop reading requests after a while
       dbus_message_set_no_reply(msg.get(), TRUE);

       dbus_connection_send(disp().conn_, msg.get(), nullptr);
       dbus_connection_flush(disp().conn_);
    }

    return rc;
}
예제 #6
0
QVariant TestItem::data(int role) const
{
  switch(role) {
  case DurationRole:
      return duration();
  case ChecksumRole:
    return checksum();
  case DependsRole:
    return depends();
  case TestNameRole:
    return testname();
  case RequiresRole:
    return requires();
  case DescriptionRole:
      return description();

  case CommandRole:
      return command();
  case EnvironRole:
      return environ();
  case PluginRole:
      return plugin();
  case TypeRole:
      return type();
  case UserRole:
      return user();
  case ViaRole:
      return via();

  case GroupRole:
      return group();
  case CheckRole:
      return check();
  case ObjectPathRole:
      return objectpath();
  case RunstatusRole:
      return runstatus();
  case ElapsedtimeRole:
      return elapsedtime();
  case GroupstatusRole:
      return groupstatus();

  case ParentNameRole:
      break;

  case ParentIdRole:
    break;

  case DepthRole:
      return depth();

  case BranchRole:
      return branch();

  case RerunRole:
      return rerun();

  default:
    return QVariant();
  }

  // Prevents non-void return warning from the compiler
  return QVariant();
}