source: filezilla/trunk/fuentes/src/dbus/wxdbusconnection.h @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 3 years ago

First release to xenial

File size: 5.4 KB
Line 
1/****************************************************************************
2
3Copyright (c) 2007 Andrei Borovsky <anb@symmetrica.net>
4
5Permission is hereby granted, free of charge, to any person obtaining a
6copy of this software and associated documentation files (the "Software"),
7to deal in the Software without restriction, including without limitation
8the rights to use, copy, modify, merge, publish, distribute, sublicense,
9and/or sell copies of the Software, and to permit persons to whom the
10Software is furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21DEALINGS IN THE SOFTWARE.
22
23****************************************************************************/
24
25#ifndef WX_DBUSCONNECTION
26#define WX_DBUSCONNECTION
27
28#include <wx/wx.h>
29#include <dbus/dbus.h>
30
31class DBusThread;
32
33class wxDBusError : public wxObject
34{
35public:
36        wxDBusError();
37        virtual ~wxDBusError();
38        DBusError &GetError();
39        bool IsErrorName(const char * name);
40        void Reset();
41        const char * GetName();
42        const char * GetMessage();
43        bool IsSet();
44private:
45        DBusError m_error;
46};
47
48class wxDBusConnectionEvent : public wxNotifyEvent
49{
50public:
51        wxDBusConnectionEvent(wxEventType commandType = wxEVT_NULL,
52          int id = 0, DBusMessage * message = NULL): wxNotifyEvent(commandType, id)
53                {m_message = message; };
54
55        wxDBusConnectionEvent(const wxDBusConnectionEvent &event): wxNotifyEvent(event)
56                {m_message = event.m_message;};
57
58        virtual wxEvent *Clone() const
59                {return new wxDBusConnectionEvent(*this);};
60
61        DBusMessage * GetMessage()
62                { return m_message; };
63
64DECLARE_DYNAMIC_CLASS(wxDBusConnectionEvent)
65private:
66        DBusMessage * m_message;
67};
68
69typedef void (wxEvtHandler::*wxDBusConnectionEventFunction)
70                                                                                (wxDBusConnectionEvent&);
71/*
72  There are three events declared for the wxDBusConnection object.
73  wxEVT_DBUS_SIGNAL informs the application about any signal that appearrs on the bus.
74  wxEVT_DBUS_NOTIFICATION informs the application about any messages that it
75  is has registered to recieve by calling RegisterObjectPath.
76  These messages may be either signals or method calls.
77  Note that all the messages that raise wxEVT_DBUS_NOTIFICATION also
78  raise wxEVT_DBUS_SIGNAL.
79  Your app may be uninterested in processing wxEVT_DBUS_SIGNAL, but it is
80  a good practice to process it anyway. Each time the event is called a copy of a D-Bus
81  message is allocated for it.
82  This copy should be freed in the event's handler. There are two ways to do it.
83  the two following handlers do nothing else but release a copy of D-BUS message:
84
85void MainFrame::OnSignal(wxDBusConnectionEvent& event)
86{
87        wxDBusMessage * msg = wxDBusMessage::ExtractFromEvent(&event);
88        delete wxDBusMessage; // when we delete this object we free an underlying D-Bus message with it.
89}
90
91****
92
93void MainFrame::OnSignal(wxDBusConnectionEvent& event)
94{
95        dbus_message_unref(event.GetMessage()); // here we call a low level D-Bus function to release the message.
96}
97
98  The wxEVT_DBUS_ASYNC_RESPONSE event is raised when a response to an asynchronous
99  method call arrives on the bus. Process this event only if you use asynchronous method calls.
100*/
101
102BEGIN_DECLARE_EVENT_TYPES()
103        DECLARE_EVENT_TYPE(wxEVT_DBUS_NOTIFICATION, wxID_ANY)
104        DECLARE_EVENT_TYPE(wxEVT_DBUS_SIGNAL,wxID_ANY)
105        DECLARE_EVENT_TYPE(wxEVT_DBUS_ASYNC_RESPONSE, wxID_ANY)
106END_DECLARE_EVENT_TYPES()
107
108#define EVT_DBUS_NOTIFICATION(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_DBUS_NOTIFICATION, id, -1, (wxObjectEventFunction) (wxEventFunction)  (wxDBusConnectionEventFunction) & fn, (wxObject *) NULL ),
109
110#define EVT_DBUS_SIGNAL(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_DBUS_SIGNAL, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxDBusConnectionEventFunction) & fn, (wxObject *) NULL ),
111
112#define EVT_DBUS_ASYNC_RESPONSE(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_DBUS_ASYNC_RESPONSE, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxDBusConnectionEventFunction) & fn, (wxObject *) NULL ),
113
114#define wxDBusConnectionEventHandler(func) (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDBusConnectionEventFunction, &func)
115
116class wxDBusConnection: public wxObject
117{
118public:
119        wxDBusConnection(int ID, wxEvtHandler * EvtHandler, bool System);
120        virtual ~wxDBusConnection();
121        inline DBusConnection * GetConnection() {return m_connection;};
122        inline int GetID() {return m_ID;};
123        inline wxEvtHandler * GetEvtHandler() {return m_EvtHandler;};
124        bool IsConnected();
125        wxDBusError &GetLastError();
126        bool Send(DBusMessage *message, dbus_uint32_t *serial);
127        bool SendWithReply(DBusMessage *message, int timeout_milliseconds);
128        DBusMessage * SendWithReplyAndBlock(DBusMessage *message, int timeout_milliseconds);
129        void Flush();
130        DBusMessage * BorrowMessage();
131        void ReturnMessage(DBusMessage * message);
132        DBusMessage * PopMessage();
133        bool RegisterObjectPath(const char *path);
134        bool UnregisterObjectPath(const char *path);
135private:
136        int m_ID{};
137        wxEvtHandler * m_EvtHandler{};
138        DBusConnection * m_connection{};
139        DBusThread * m_thread{};
140        wxDBusError * m_error{};
141        bool m_filter_installed{};
142};
143
144#endif
Note: See TracBrowser for help on using the repository browser.