• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  *
24  * must be included manually as
25  *
26  *  #include <libwebsockets/lws-dbus.h>
27  *
28  * if dbus apis needed
29  */
30 
31 #if !defined(__LWS_DBUS_H__)
32 #define __LWS_DBUS_H__
33 
34 #include <dbus/dbus.h>
35 
36 /* helper type to simplify implementing methods as individual functions */
37 typedef DBusHandlerResult (*lws_dbus_message_handler)(DBusConnection *conn,
38 			   DBusMessage *message, DBusMessage **reply, void *d);
39 
40 struct lws_dbus_ctx;
41 typedef void (*lws_dbus_closing_t)(struct lws_dbus_ctx *ctx);
42 
43 struct lws_dbus_ctx {
44 	struct lws_dll2_owner owner; /* dbusserver ctx: HEAD of accepted list */
45 	struct lws_dll2 next; /* dbusserver ctx: HEAD of accepted list */
46 	struct lws_vhost *vh; /* the vhost we logically bind to in lws */
47 	int tsi;	/* the lws thread service index (0 if only one service
48 			   thread as is the default */
49 	DBusConnection *conn;
50 	DBusServer *dbs;
51 	DBusWatch *w[4];
52  	DBusPendingCall *pc;
53 
54  	char hup;
55  	char timeouts;
56 
57  	/* cb_closing callback will be called after the connection and this
58  	 * related ctx struct have effectively gone out of scope.
59  	 *
60  	 * The callback should close and clean up the connection and free the
61  	 * ctx.
62  	 */
63  	lws_dbus_closing_t cb_closing;
64 };
65 
66 /**
67  * lws_dbus_connection_setup() - bind dbus connection object to lws event loop
68  *
69  * \param ctx: additional information about the connection
70  * \param conn: the DBusConnection object to bind
71  *
72  * This configures a DBusConnection object to use lws for watchers and timeout
73  * operations.
74  */
75 LWS_VISIBLE LWS_EXTERN int
76 lws_dbus_connection_setup(struct lws_dbus_ctx *ctx, DBusConnection *conn,
77 			  lws_dbus_closing_t cb_closing);
78 
79 /**
80  * lws_dbus_server_listen() - bind dbus connection object to lws event loop
81  *
82  * \param ctx: additional information about the connection
83  * \param ads: the DBUS address to listen on, eg, "unix:abstract=mysocket"
84  * \param err: a DBusError object to take any extra error information
85  * \param new_conn: a callback function to prepare new accepted connections
86  *
87  * This creates a DBusServer and binds it to the lws event loop, and your
88  * callback to accept new connections.
89  */
90 LWS_VISIBLE LWS_EXTERN DBusServer *
91 lws_dbus_server_listen(struct lws_dbus_ctx *ctx, const char *ads,
92 		       DBusError *err, DBusNewConnectionFunction new_conn);
93 
94 #endif
95