2 * This file is part of buxton.
4 * Copyright (C) 2013 Intel Corporation
6 * buxton is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
13 * \file protocol.h Internal header
14 * This file is used internally by buxton to provide functionality
15 * used for the wire protocol
24 #include "buxtonclient.h"
25 #include "buxtonkey.h"
27 #include "serialize.h"
31 * Initialize callback hashamps
32 * @return a boolean value, indicating success of the operation
34 bool setup_callbacks(void)
35 __attribute__((warn_unused_result));
38 * free callback hashmaps
40 void cleanup_callbacks(void);
43 * Execute callback function on list using user data
44 * @param callback User callback function executed
45 * @param data User data passed to callback function
46 * @param count number of elements in list
47 * @param list Data from buxtond
48 * @param type Message type of the callback
49 * @param key Key used to make the request
51 void run_callback(BuxtonCallback callback, void *data, size_t count,
52 BuxtonData *list, BuxtonControlMessage type,
56 * cleanup expired messages (must hold callback_guard lock)
58 void reap_callbacks(void);
61 * Write message to buxtond
62 * @param client Client connection
63 * @param send serialized data to send to buxtond
64 * @param send_len size of send
65 * @param callback Callback function used to handle buxtond's response
66 * @param data User data passed to callback function
67 * @param msgid Message id used to identify buxtond's response
68 * @param type The type of request being sent to buxtond
69 * @return a boolean value, indicating success of the operation
71 bool send_message(_BuxtonClient *client, uint8_t *send, size_t send_len,
72 BuxtonCallback callback, void *data, uint32_t msgid,
73 BuxtonControlMessage type, _BuxtonKey *key)
74 __attribute__((warn_unused_result));
77 * Check for callbacks for daemon's response
78 * @param msg Buxton message type
79 * @param msgid Key for message lookup
80 * @param list array of BuxtonData
81 * @param count number of elements in list
83 void handle_callback_response(BuxtonControlMessage msg, uint32_t msgid,
84 BuxtonData *list, size_t count);
87 * Parse responses from buxtond and run callbacks on received messages
88 * @param client A BuxtonClient
89 * @return number of received messages processed
92 ssize_t buxton_wire_handle_response(_BuxtonClient *client)
93 __attribute__((warn_unused_result));
96 * Wait for a response from buxtond and then call handle response
97 * @param client Client connection
98 * @return an int value, indicating success of the operation
100 int buxton_wire_get_response(_BuxtonClient *client);
103 * Send a SET message over the wire protocol, return the response
104 * @param client Client connection
105 * @param key _BuxtonKey pointer
106 * @param value A pointer to a new value
107 * @param data A BuxtonData storing the new value
108 * @param callback A callback function to handle daemon reply
109 * @param data User data to be used with callback function
110 * @return a boolean value, indicating success of the operation
112 bool buxton_wire_set_value(_BuxtonClient *client, _BuxtonKey *key, void *value,
113 BuxtonCallback callback, void *data)
114 __attribute__((warn_unused_result));
117 * Send a SET_LABEL message over the wire protocol, return the response
119 * @note This is a privileged operation, so it will return false for unprivileged clients
121 * @param client Client connection
122 * @param key Key or group name
123 * @param value Key or group label
124 * @param callback A callback function to handle daemon reply
125 * @param data User data to be used with callback function
126 * @return a boolean value, indicating success of the operation
128 bool buxton_wire_set_label(_BuxtonClient *client, _BuxtonKey *key,
129 BuxtonString *value, BuxtonCallback callback,
131 __attribute__((warn_unused_result));
134 * Send a CREATE_GROUP message over the wire protocol, return the response
136 * @note This is a privileged operation, so it will return false for unprivileged clients
138 * @param client Client connection
139 * @param key Key with group and layer members initialized
140 * @param callback A callback function to handle daemon reply
141 * @param data User data to be used with callback function
142 * @return a boolean value, indicating success of the operation
144 bool buxton_wire_create_group(_BuxtonClient *client, _BuxtonKey *key,
145 BuxtonCallback callback, void *data)
146 __attribute__((warn_unused_result));
149 * Send a REMOVE_GROUP message over the wire protocol, return the response
151 * @note This is a privileged operation, so it will return false for unprivileged clients
153 * @param client Client connection
154 * @param key Key with group and layer members initialized
155 * @param callback A callback function to handle daemon reply
156 * @param data User data to be used with callback function
157 * @return a boolean value, indicating success of the operation
159 bool buxton_wire_remove_group(_BuxtonClient *client, _BuxtonKey *key,
160 BuxtonCallback callback, void *data)
161 __attribute__((warn_unused_result));
164 * Send a GET message over the wire protocol, return the data
165 * @param client Client connection
166 * @param key _BuxtonKey pointer
167 * @param callback A callback function to handle daemon reply
168 * @param data User data to be used with callback functionb
169 * @return a boolean value, indicating success of the operation
171 bool buxton_wire_get_value(_BuxtonClient *client, _BuxtonKey *key,
172 BuxtonCallback callback, void *data)
173 __attribute__((warn_unused_result));
177 * Send an UNSET message over the wire protocol, return the response
178 * @param client Client connection
179 * @param key _BuxtonKey pointer
180 * @param callback A callback function to handle daemon reply
181 * @param data User data to be used with callback function
182 * @return a boolean value, indicating success of the operation
184 bool buxton_wire_unset_value(_BuxtonClient *client,
186 BuxtonCallback callback,
188 __attribute__((warn_unused_result));
190 * Send a NOTIFY message over the protocol, register for events
191 * @param client Client connection
192 * @param key _BuxtonKey pointer
193 * @param callback A callback function to handle daemon reply
194 * @param data User data to be used with callback function
195 * @return a boolean value, indicating success of the operation
197 bool buxton_wire_register_notification(_BuxtonClient *client,
199 BuxtonCallback callback,
201 __attribute__((warn_unused_result));
204 * Send a LIST message over the protocol, retrieve key list
205 * @param client Client connection
206 * @param layer Layer name
207 * @param callback A callback function to handle daemon reply
208 * @param data User data to be used with callback function
209 * @return a boolean value, indicating success of the operation
211 bool buxton_wire_list_keys(_BuxtonClient *client,
213 BuxtonCallback callback,
215 __attribute__((warn_unused_result));
218 * Send an UNNOTIFY message over the protocol, no longer recieve events
219 * @param client Client connection
220 * @param key _BuxtonKey pointer
221 * @param callback A callback function to handle daemon reply
222 * @param data User data to be used with callback function
223 * @return a boolean value, indicating success of the operation
225 bool buxton_wire_unregister_notification(_BuxtonClient *client,
227 BuxtonCallback callback,
229 __attribute__((warn_unused_result));
231 void include_protocol(void);
234 * Editor modelines - http://www.wireshark.org/tools/modelines.html
239 * indent-tabs-mode: t
242 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
243 * :indentSize=8:tabSize=8:noTabs=false: