Make d-bus available to orca if someone decides they want to implement it.
This commit is contained in:
1 parent
c3e981b4c2
commit
0f59809e9a
11 files changed
+374
-39
No files matched your search
+9
-10
@@ -8,8 +8,6 @@
|
||||
#include <unistd.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char *reader = "org.stormux.Cthulhu1.Service";
|
||||
constexpr const char *reader_path = "/org/stormux/Cthulhu1/Service";
|
||||
constexpr const char *path = "/org/stormux/Cthulhu1/WineReview";
|
||||
constexpr const char *xml = R"(<node><interface name="org.stormux.Cthulhu1.WineReview">
|
||||
<method name="CaptureWindow"><arg type="s" direction="in"/><arg type="s" direction="in"/>
|
||||
@@ -72,13 +70,14 @@ struct Job {
|
||||
} // namespace
|
||||
|
||||
struct ReviewService::State {
|
||||
explicit State(GDBusConnection *c,ReviewIdentityStore &s):connection(G_DBUS_CONNECTION(g_object_ref(c))),store(s) {
|
||||
explicit State(GDBusConnection *c,ReviewIdentityStore &s,const ReaderEndpoint &reader):connection(G_DBUS_CONNECTION(g_object_ref(c))),store(s),endpoint(reader) {
|
||||
context=g_main_context_new(); loop=g_main_loop_new(context,FALSE);
|
||||
calls=g_cancellable_new();
|
||||
}
|
||||
~State() { g_object_unref(calls); g_main_loop_unref(loop); g_main_context_unref(context); g_object_unref(connection); }
|
||||
GDBusConnection *connection;
|
||||
ReviewIdentityStore store;
|
||||
const ReaderEndpoint endpoint;
|
||||
GMainContext *context;
|
||||
GMainLoop *loop;
|
||||
GCancellable *calls;
|
||||
@@ -106,7 +105,7 @@ struct ReviewService::State {
|
||||
std::string lookup_owner() {
|
||||
GError *error=nullptr;
|
||||
GVariant *value=g_dbus_connection_call_sync(connection,"org.freedesktop.DBus","/org/freedesktop/DBus",
|
||||
"org.freedesktop.DBus","GetNameOwner",g_variant_new("(s)",reader),G_VARIANT_TYPE("(s)"),
|
||||
"org.freedesktop.DBus","GetNameOwner",g_variant_new("(s)",endpoint.busName),G_VARIANT_TYPE("(s)"),
|
||||
G_DBUS_CALL_FLAGS_NONE,100,nullptr,&error);
|
||||
std::string result;
|
||||
if (value) { const gchar *name=nullptr; g_variant_get(value,"(&s)",&name); result=name; g_variant_unref(value); }
|
||||
@@ -145,7 +144,7 @@ struct ReviewService::State {
|
||||
if (now<next_registration) return;
|
||||
next_registration=now+1000;
|
||||
GError *error=nullptr;
|
||||
GVariant *value=g_dbus_connection_call_sync(connection,owner.c_str(),reader_path,reader,"RegisterWineReviewProvider",
|
||||
GVariant *value=g_dbus_connection_call_sync(connection,owner.c_str(),endpoint.objectPath,endpoint.interfaceName,"RegisterWineReviewProvider",
|
||||
g_variant_new("(ou)",path,1u),G_VARIANT_TYPE("(b)"),G_DBUS_CALL_FLAGS_NONE,100,nullptr,&error);
|
||||
gboolean accepted=FALSE;
|
||||
if (value) { g_variant_get(value,"(b)",&accepted); g_variant_unref(value); }
|
||||
@@ -156,7 +155,7 @@ struct ReviewService::State {
|
||||
{ std::lock_guard<std::mutex> lock(mutex); notice=focus; }
|
||||
if (!registered || notice.focus.empty() || same_notice(notice,sent)) return;
|
||||
sent=notice; announcing=true;
|
||||
g_dbus_connection_call(connection,owner.c_str(),reader_path,reader,"PresentWineReviewFocus",
|
||||
g_dbus_connection_call(connection,owner.c_str(),endpoint.objectPath,endpoint.interfaceName,"PresentWineReviewFocus",
|
||||
g_variant_new("(ssstssb(iiii))",notice.instance.c_str(),notice.window.c_str(),notice.focus.c_str(),notice.revision,
|
||||
notice.title.c_str(),notice.role.c_str(),notice.protected_text,notice.bounds.left,notice.bounds.top,
|
||||
notice.bounds.right-notice.bounds.left,notice.bounds.bottom-notice.bounds.top),
|
||||
@@ -167,7 +166,7 @@ struct ReviewService::State {
|
||||
auto &state=*static_cast<State*>(data);
|
||||
const uint64_t received=GetTickCount64();
|
||||
if (!state.same_user || state.owner!=sender || state.lookup_owner()!=sender) {
|
||||
g_dbus_method_invocation_return_dbus_error(invocation,"org.freedesktop.DBus.Error.AccessDenied","Only the current Cthulhu service may capture Wine review."); return;
|
||||
g_dbus_method_invocation_return_dbus_error(invocation,"org.freedesktop.DBus.Error.AccessDenied","Only the current selected reader service may capture Wine review."); return;
|
||||
}
|
||||
const char *window=nullptr,*focus=nullptr; guint64 revision=0;
|
||||
g_variant_get(parameters,"(&s&st)",&window,&focus,&revision);
|
||||
@@ -224,9 +223,9 @@ DWORD WINAPI ReviewService::State::work(LPVOID pointer) {
|
||||
{ std::lock_guard<std::mutex> lock(state->mutex); state->worker_done=true; state->changed.notify_all(); }
|
||||
return 0;
|
||||
}
|
||||
bool ReviewService::start(GDBusConnection *connection,ReviewIdentityStore &store) {
|
||||
bool ReviewService::start(GDBusConnection *connection,ReviewIdentityStore &store,const ReaderEndpoint &endpoint) {
|
||||
if (state_) return false;
|
||||
state_=std::make_shared<State>(connection,store);
|
||||
state_=std::make_shared<State>(connection,store,endpoint);
|
||||
auto state=state_;
|
||||
auto worker_state=new std::shared_ptr<State>(state);
|
||||
worker_=CreateThread(nullptr,0,State::work,worker_state,0,nullptr);
|
||||
@@ -267,7 +266,7 @@ DWORD WINAPI ReviewService::State::dispatch(LPVOID pointer) {
|
||||
},new std::shared_ptr<State>(state),[](gpointer p) { delete static_cast<std::shared_ptr<State>*>(p); });
|
||||
g_source_attach(tick,state->context);
|
||||
state->owner_subscription=g_dbus_connection_signal_subscribe(state->connection,"org.freedesktop.DBus","org.freedesktop.DBus",
|
||||
"NameOwnerChanged","/org/freedesktop/DBus",reader,G_DBUS_SIGNAL_FLAGS_NONE,
|
||||
"NameOwnerChanged","/org/freedesktop/DBus",state->endpoint.busName,G_DBUS_SIGNAL_FLAGS_NONE,
|
||||
[](GDBusConnection*,const gchar*,const gchar*,const gchar*,const gchar*,GVariant*,gpointer p) {
|
||||
static_cast<State*>(p)->refresh_owner();
|
||||
},state.get(),nullptr);
|
||||
|
||||
Reference in new issue
Block a user