Ожидание сервиса DBus быть доступным в QT

Язык:

  • загрязнение Пространства имен путем создания большого места переменных в глобальном контексте.

  • обработчики Событий привязки в форме 'foo.onclick = myFunc' (нерастяжимый, должен использовать attachEvent/addEventListener).

  • Используя оценку почти в любом non-JSON контексте

  • Почти каждое использование document.write (используют методы DOM как document.createElement)

  • Разработка прототипа против Объектного объекта (БУМ!)

  • А маленький это, но выполнение больших количеств строки concats с '+' (создание массива и присоединение к нему намного более эффективны)

  • что касается несуществующего undefined постоянный

Дизайн/Развертывание:

  • (Обычно) не обеспечение noscript поддержка.

  • Не упаковка Вашего кода в единственный ресурс

  • встроенное Помещение (т.е. тело) сценарии около вершины тела (они блочная загрузка)

конкретный Ajax:

  • не указание на запуск, конец или ошибку запроса пользователю

  • опрос

  • передача и парсинг XML вместо JSON или HTML (где соответствующий)

редактирование: Я продолжаю думать о больше!

12
задан jesup 15 September 2009 в 19:56
поделиться

1 ответ

Ok, since no one answered, I've found the answer in the meantime:

You want to watch NameOwnerChanged:

// subscribe to notifications about when a service is registered/unregistered
   connect(QDBusConnection::sessionBus().interface(),
           SIGNAL(serviceOwnerChanged(QString,QString,QString)),
           this,SLOT(serviceOwnerChanged(QString,QString,QString)));

and

void 
VcsApplicationController::serviceOwnerChanged(const QString &name,
                                              const QString &oldOwner,
                                              const QString &newOwner)
{
    Q_UNUSED(oldOwner);
    if (name == "com.foo.bar.FooService")
    {
        qLog(Whatever) << "serviceOwnerChanged" << name << oldOwner << newOwner;
        if (!newOwner.isEmpty())
        {
            // New owner in town
            emit Initialized();
            // or if you control the interface and both sides, you can wait for
            // a "Ready()" signal before declaring FooService ready for business.
        }
        else
        {
            // indicate we've lost connection, etc
            emit Uninitialized();
        }
    }
}

Note that there may be race conditions with doing methods on FooService from within serviceOwnerChanged - I'm not sure yet if they're a side-effect of the binding (dbus-c++ in my test case), or inherent in the design of dbus (possible - no on on the dbus mailing list will answer the question). If there is a real race condition, you can wait on a Ready()/whatever signal, if you control the DBus API. If you don't control the other end, you can add a very short delay or you can also watch AddMatch() to make sure the new owner has added a match on the name as well.

10
ответ дан 2 December 2019 в 21:03
поделиться
Другие вопросы по тегам:

Похожие вопросы: