Imported Upstream version 3.2.0
[platform/upstream/libwebsockets.git] / include / libwebsockets / lws-dbus.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010-2019 Andy Green <andy@warmcat.com>
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public
8  *  License as published by the Free Software Foundation:
9  *  version 2.1 of the License.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  *  MA  02110-1301  USA
20  *
21  * must be included manually as
22  *
23  *  #include <libwebsockets/lws-dbus.h>
24  *
25  * if dbus apis needed
26  */
27
28 #if !defined(__LWS_DBUS_H__)
29 #define __LWS_DBUS_H__
30
31 #include <dbus/dbus.h>
32
33 /* helper type to simplify implementing methods as individual functions */
34 typedef DBusHandlerResult (*lws_dbus_message_handler)(DBusConnection *conn,
35                            DBusMessage *message, DBusMessage **reply, void *d);
36
37 struct lws_dbus_ctx;
38 typedef void (*lws_dbus_closing_t)(struct lws_dbus_ctx *ctx);
39
40 struct lws_dbus_ctx {
41         struct lws_dll2_owner owner; /* dbusserver ctx: HEAD of accepted list */
42         struct lws_dll2 next; /* dbusserver ctx: HEAD of accepted list */
43         struct lws_vhost *vh; /* the vhost we logically bind to in lws */
44         int tsi;        /* the lws thread service index (0 if only one service
45                            thread as is the default */
46         DBusConnection *conn;
47         DBusServer *dbs;
48         DBusWatch *w[4];
49         DBusPendingCall *pc;
50
51         char hup;
52         char timeouts;
53
54         /* cb_closing callback will be called after the connection and this
55          * related ctx struct have effectively gone out of scope.
56          *
57          * The callback should close and clean up the connection and free the
58          * ctx.
59          */
60         lws_dbus_closing_t cb_closing;
61 };
62
63 /**
64  * lws_dbus_connection_setup() - bind dbus connection object to lws event loop
65  *
66  * \param ctx: additional information about the connection
67  * \param conn: the DBusConnection object to bind
68  *
69  * This configures a DBusConnection object to use lws for watchers and timeout
70  * operations.
71  */
72 LWS_VISIBLE LWS_EXTERN int
73 lws_dbus_connection_setup(struct lws_dbus_ctx *ctx, DBusConnection *conn,
74                           lws_dbus_closing_t cb_closing);
75
76 /**
77  * lws_dbus_server_listen() - bind dbus connection object to lws event loop
78  *
79  * \param ctx: additional information about the connection
80  * \param ads: the DBUS address to listen on, eg, "unix:abstract=mysocket"
81  * \param err: a DBusError object to take any extra error information
82  * \param new_conn: a callback function to prepare new accepted connections
83  *
84  * This creates a DBusServer and binds it to the lws event loop, and your
85  * callback to accept new connections.
86  */
87 LWS_VISIBLE LWS_EXTERN DBusServer *
88 lws_dbus_server_listen(struct lws_dbus_ctx *ctx, const char *ads,
89                        DBusError *err, DBusNewConnectionFunction new_conn);
90
91 #endif