Path: blob/master/thirdparty/linuxbsd_headers/dbus/dbus-connection.h
9898 views
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */1/* dbus-connection.h DBusConnection object2*3* Copyright (C) 2002, 2003 Red Hat Inc.4*5* Licensed under the Academic Free License version 2.16*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2 of the License, or10* (at your option) any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA20*21*/22#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)23#error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents."24#endif2526#ifndef DBUS_CONNECTION_H27#define DBUS_CONNECTION_H2829#include <dbus/dbus-errors.h>30#include <dbus/dbus-macros.h>31#include <dbus/dbus-memory.h>32#include <dbus/dbus-message.h>33#include <dbus/dbus-shared.h>3435DBUS_BEGIN_DECLS3637/**38* @addtogroup DBusConnection39* @{40*/4142/* documented in dbus-watch.c */43typedef struct DBusWatch DBusWatch;44/* documented in dbus-timeout.c */45typedef struct DBusTimeout DBusTimeout;46/** Opaque type representing preallocated resources so a message can be sent without further memory allocation. */47typedef struct DBusPreallocatedSend DBusPreallocatedSend;48/** Opaque type representing a method call that has not yet received a reply. */49typedef struct DBusPendingCall DBusPendingCall;50/** Opaque type representing a connection to a remote application and associated incoming/outgoing message queues. */51typedef struct DBusConnection DBusConnection;52/** Set of functions that must be implemented to handle messages sent to a particular object path. */53typedef struct DBusObjectPathVTable DBusObjectPathVTable;5455/**56* Indicates the status of a #DBusWatch.57*/58typedef enum59{60DBUS_WATCH_READABLE = 1 << 0, /**< As in POLLIN */61DBUS_WATCH_WRITABLE = 1 << 1, /**< As in POLLOUT */62DBUS_WATCH_ERROR = 1 << 2, /**< As in POLLERR (can't watch for63* this, but can be present in64* current state passed to65* dbus_watch_handle()).66*/67DBUS_WATCH_HANGUP = 1 << 3 /**< As in POLLHUP (can't watch for68* it, but can be present in current69* state passed to70* dbus_watch_handle()).71*/72/* Internal to libdbus, there is also _DBUS_WATCH_NVAL in dbus-watch.h */73} DBusWatchFlags;7475/**76* Indicates the status of incoming data on a #DBusConnection. This determines whether77* dbus_connection_dispatch() needs to be called.78*/79typedef enum80{81DBUS_DISPATCH_DATA_REMAINS, /**< There is more data to potentially convert to messages. */82DBUS_DISPATCH_COMPLETE, /**< All currently available data has been processed. */83DBUS_DISPATCH_NEED_MEMORY /**< More memory is needed to continue. */84} DBusDispatchStatus;8586/** Called when libdbus needs a new watch to be monitored by the main87* loop. Returns #FALSE if it lacks enough memory to add the88* watch. Set by dbus_connection_set_watch_functions() or89* dbus_server_set_watch_functions().90*/91typedef dbus_bool_t (* DBusAddWatchFunction) (DBusWatch *watch,92void *data);93/** Called when dbus_watch_get_enabled() may return a different value94* than it did before. Set by dbus_connection_set_watch_functions()95* or dbus_server_set_watch_functions().96*/97typedef void (* DBusWatchToggledFunction) (DBusWatch *watch,98void *data);99/** Called when libdbus no longer needs a watch to be monitored by the100* main loop. Set by dbus_connection_set_watch_functions() or101* dbus_server_set_watch_functions().102*/103typedef void (* DBusRemoveWatchFunction) (DBusWatch *watch,104void *data);105/** Called when libdbus needs a new timeout to be monitored by the main106* loop. Returns #FALSE if it lacks enough memory to add the107* watch. Set by dbus_connection_set_timeout_functions() or108* dbus_server_set_timeout_functions().109*/110typedef dbus_bool_t (* DBusAddTimeoutFunction) (DBusTimeout *timeout,111void *data);112/** Called when dbus_timeout_get_enabled() may return a different113* value than it did before.114* Set by dbus_connection_set_timeout_functions() or115* dbus_server_set_timeout_functions().116*/117typedef void (* DBusTimeoutToggledFunction) (DBusTimeout *timeout,118void *data);119/** Called when libdbus no longer needs a timeout to be monitored by the120* main loop. Set by dbus_connection_set_timeout_functions() or121* dbus_server_set_timeout_functions().122*/123typedef void (* DBusRemoveTimeoutFunction) (DBusTimeout *timeout,124void *data);125/** Called when the return value of dbus_connection_get_dispatch_status()126* may have changed. Set with dbus_connection_set_dispatch_status_function().127*/128typedef void (* DBusDispatchStatusFunction) (DBusConnection *connection,129DBusDispatchStatus new_status,130void *data);131/**132* Called when the main loop's thread should be notified that there's now work133* to do. Set with dbus_connection_set_wakeup_main_function().134*/135typedef void (* DBusWakeupMainFunction) (void *data);136137/**138* Called during authentication to check whether the given UNIX user139* ID is allowed to connect, if the client tried to auth as a UNIX140* user ID. Normally on Windows this would never happen. Set with141* dbus_connection_set_unix_user_function().142*/143typedef dbus_bool_t (* DBusAllowUnixUserFunction) (DBusConnection *connection,144unsigned long uid,145void *data);146147/**148* Called during authentication to check whether the given Windows user149* ID is allowed to connect, if the client tried to auth as a Windows150* user ID. Normally on UNIX this would never happen. Set with151* dbus_connection_set_windows_user_function().152*/153typedef dbus_bool_t (* DBusAllowWindowsUserFunction) (DBusConnection *connection,154const char *user_sid,155void *data);156157158/**159* Called when a pending call now has a reply available. Set with160* dbus_pending_call_set_notify().161*/162typedef void (* DBusPendingCallNotifyFunction) (DBusPendingCall *pending,163void *user_data);164165/**166* Called when a message needs to be handled. The result indicates whether or167* not more handlers should be run. Set with dbus_connection_add_filter().168*/169typedef DBusHandlerResult (* DBusHandleMessageFunction) (DBusConnection *connection,170DBusMessage *message,171void *user_data);172DBUS_EXPORT173DBusConnection* dbus_connection_open (const char *address,174DBusError *error);175DBUS_EXPORT176DBusConnection* dbus_connection_open_private (const char *address,177DBusError *error);178DBUS_EXPORT179DBusConnection* dbus_connection_ref (DBusConnection *connection);180DBUS_EXPORT181void dbus_connection_unref (DBusConnection *connection);182DBUS_EXPORT183void dbus_connection_close (DBusConnection *connection);184DBUS_EXPORT185dbus_bool_t dbus_connection_get_is_connected (DBusConnection *connection);186DBUS_EXPORT187dbus_bool_t dbus_connection_get_is_authenticated (DBusConnection *connection);188DBUS_EXPORT189dbus_bool_t dbus_connection_get_is_anonymous (DBusConnection *connection);190DBUS_EXPORT191char* dbus_connection_get_server_id (DBusConnection *connection);192DBUS_EXPORT193dbus_bool_t dbus_connection_can_send_type (DBusConnection *connection,194int type);195196DBUS_EXPORT197void dbus_connection_set_exit_on_disconnect (DBusConnection *connection,198dbus_bool_t exit_on_disconnect);199DBUS_EXPORT200void dbus_connection_flush (DBusConnection *connection);201DBUS_EXPORT202dbus_bool_t dbus_connection_read_write_dispatch (DBusConnection *connection,203int timeout_milliseconds);204DBUS_EXPORT205dbus_bool_t dbus_connection_read_write (DBusConnection *connection,206int timeout_milliseconds);207DBUS_EXPORT208DBusMessage* dbus_connection_borrow_message (DBusConnection *connection);209DBUS_EXPORT210void dbus_connection_return_message (DBusConnection *connection,211DBusMessage *message);212DBUS_EXPORT213void dbus_connection_steal_borrowed_message (DBusConnection *connection,214DBusMessage *message);215DBUS_EXPORT216DBusMessage* dbus_connection_pop_message (DBusConnection *connection);217DBUS_EXPORT218DBusDispatchStatus dbus_connection_get_dispatch_status (DBusConnection *connection);219DBUS_EXPORT220DBusDispatchStatus dbus_connection_dispatch (DBusConnection *connection);221DBUS_EXPORT222dbus_bool_t dbus_connection_has_messages_to_send (DBusConnection *connection);223DBUS_EXPORT224dbus_bool_t dbus_connection_send (DBusConnection *connection,225DBusMessage *message,226dbus_uint32_t *client_serial);227DBUS_EXPORT228dbus_bool_t dbus_connection_send_with_reply (DBusConnection *connection,229DBusMessage *message,230DBusPendingCall **pending_return,231int timeout_milliseconds);232DBUS_EXPORT233DBusMessage * dbus_connection_send_with_reply_and_block (DBusConnection *connection,234DBusMessage *message,235int timeout_milliseconds,236DBusError *error);237DBUS_EXPORT238dbus_bool_t dbus_connection_set_watch_functions (DBusConnection *connection,239DBusAddWatchFunction add_function,240DBusRemoveWatchFunction remove_function,241DBusWatchToggledFunction toggled_function,242void *data,243DBusFreeFunction free_data_function);244DBUS_EXPORT245dbus_bool_t dbus_connection_set_timeout_functions (DBusConnection *connection,246DBusAddTimeoutFunction add_function,247DBusRemoveTimeoutFunction remove_function,248DBusTimeoutToggledFunction toggled_function,249void *data,250DBusFreeFunction free_data_function);251DBUS_EXPORT252void dbus_connection_set_wakeup_main_function (DBusConnection *connection,253DBusWakeupMainFunction wakeup_main_function,254void *data,255DBusFreeFunction free_data_function);256DBUS_EXPORT257void dbus_connection_set_dispatch_status_function (DBusConnection *connection,258DBusDispatchStatusFunction function,259void *data,260DBusFreeFunction free_data_function);261DBUS_EXPORT262dbus_bool_t dbus_connection_get_unix_user (DBusConnection *connection,263unsigned long *uid);264DBUS_EXPORT265dbus_bool_t dbus_connection_get_unix_process_id (DBusConnection *connection,266unsigned long *pid);267DBUS_EXPORT268dbus_bool_t dbus_connection_get_adt_audit_session_data (DBusConnection *connection,269void **data,270dbus_int32_t *data_size);271DBUS_EXPORT272void dbus_connection_set_unix_user_function (DBusConnection *connection,273DBusAllowUnixUserFunction function,274void *data,275DBusFreeFunction free_data_function);276DBUS_EXPORT277dbus_bool_t dbus_connection_get_windows_user (DBusConnection *connection,278char **windows_sid_p);279DBUS_EXPORT280void dbus_connection_set_windows_user_function (DBusConnection *connection,281DBusAllowWindowsUserFunction function,282void *data,283DBusFreeFunction free_data_function);284DBUS_EXPORT285void dbus_connection_set_allow_anonymous (DBusConnection *connection,286dbus_bool_t value);287DBUS_EXPORT288void dbus_connection_set_route_peer_messages (DBusConnection *connection,289dbus_bool_t value);290291292/* Filters */293294DBUS_EXPORT295dbus_bool_t dbus_connection_add_filter (DBusConnection *connection,296DBusHandleMessageFunction function,297void *user_data,298DBusFreeFunction free_data_function);299DBUS_EXPORT300void dbus_connection_remove_filter (DBusConnection *connection,301DBusHandleMessageFunction function,302void *user_data);303304305/* Other */306DBUS_EXPORT307dbus_bool_t dbus_connection_allocate_data_slot (dbus_int32_t *slot_p);308DBUS_EXPORT309void dbus_connection_free_data_slot (dbus_int32_t *slot_p);310DBUS_EXPORT311dbus_bool_t dbus_connection_set_data (DBusConnection *connection,312dbus_int32_t slot,313void *data,314DBusFreeFunction free_data_func);315DBUS_EXPORT316void* dbus_connection_get_data (DBusConnection *connection,317dbus_int32_t slot);318319DBUS_EXPORT320void dbus_connection_set_change_sigpipe (dbus_bool_t will_modify_sigpipe);321322DBUS_EXPORT323void dbus_connection_set_max_message_size (DBusConnection *connection,324long size);325DBUS_EXPORT326long dbus_connection_get_max_message_size (DBusConnection *connection);327DBUS_EXPORT328void dbus_connection_set_max_received_size (DBusConnection *connection,329long size);330DBUS_EXPORT331long dbus_connection_get_max_received_size (DBusConnection *connection);332333DBUS_EXPORT334void dbus_connection_set_max_message_unix_fds (DBusConnection *connection,335long n);336DBUS_EXPORT337long dbus_connection_get_max_message_unix_fds (DBusConnection *connection);338DBUS_EXPORT339void dbus_connection_set_max_received_unix_fds(DBusConnection *connection,340long n);341DBUS_EXPORT342long dbus_connection_get_max_received_unix_fds(DBusConnection *connection);343344DBUS_EXPORT345long dbus_connection_get_outgoing_size (DBusConnection *connection);346DBUS_EXPORT347long dbus_connection_get_outgoing_unix_fds (DBusConnection *connection);348349DBUS_EXPORT350DBusPreallocatedSend* dbus_connection_preallocate_send (DBusConnection *connection);351DBUS_EXPORT352void dbus_connection_free_preallocated_send (DBusConnection *connection,353DBusPreallocatedSend *preallocated);354DBUS_EXPORT355void dbus_connection_send_preallocated (DBusConnection *connection,356DBusPreallocatedSend *preallocated,357DBusMessage *message,358dbus_uint32_t *client_serial);359360361/* Object tree functionality */362363/**364* Called when a #DBusObjectPathVTable is unregistered (or its connection is freed).365* Found in #DBusObjectPathVTable.366*/367typedef void (* DBusObjectPathUnregisterFunction) (DBusConnection *connection,368void *user_data);369/**370* Called when a message is sent to a registered object path. Found in371* #DBusObjectPathVTable which is registered with dbus_connection_register_object_path()372* or dbus_connection_register_fallback().373*/374typedef DBusHandlerResult (* DBusObjectPathMessageFunction) (DBusConnection *connection,375DBusMessage *message,376void *user_data);377378/**379* Virtual table that must be implemented to handle a portion of the380* object path hierarchy. Attach the vtable to a particular path using381* dbus_connection_register_object_path() or382* dbus_connection_register_fallback().383*/384struct DBusObjectPathVTable385{386DBusObjectPathUnregisterFunction unregister_function; /**< Function to unregister this handler */387DBusObjectPathMessageFunction message_function; /**< Function to handle messages */388389void (* dbus_internal_pad1) (void *); /**< Reserved for future expansion */390void (* dbus_internal_pad2) (void *); /**< Reserved for future expansion */391void (* dbus_internal_pad3) (void *); /**< Reserved for future expansion */392void (* dbus_internal_pad4) (void *); /**< Reserved for future expansion */393};394395DBUS_EXPORT396dbus_bool_t dbus_connection_try_register_object_path (DBusConnection *connection,397const char *path,398const DBusObjectPathVTable *vtable,399void *user_data,400DBusError *error);401402DBUS_EXPORT403dbus_bool_t dbus_connection_register_object_path (DBusConnection *connection,404const char *path,405const DBusObjectPathVTable *vtable,406void *user_data);407408DBUS_EXPORT409dbus_bool_t dbus_connection_try_register_fallback (DBusConnection *connection,410const char *path,411const DBusObjectPathVTable *vtable,412void *user_data,413DBusError *error);414415DBUS_EXPORT416dbus_bool_t dbus_connection_register_fallback (DBusConnection *connection,417const char *path,418const DBusObjectPathVTable *vtable,419void *user_data);420DBUS_EXPORT421dbus_bool_t dbus_connection_unregister_object_path (DBusConnection *connection,422const char *path);423424DBUS_EXPORT425dbus_bool_t dbus_connection_get_object_path_data (DBusConnection *connection,426const char *path,427void **data_p);428429DBUS_EXPORT430dbus_bool_t dbus_connection_list_registered (DBusConnection *connection,431const char *parent_path,432char ***child_entries);433434DBUS_EXPORT435dbus_bool_t dbus_connection_get_unix_fd (DBusConnection *connection,436int *fd);437DBUS_EXPORT438dbus_bool_t dbus_connection_get_socket (DBusConnection *connection,439int *fd);440441/**442* Clear a variable or struct member that contains a #DBusConnection.443* If it does not contain #NULL, the connection that was previously444* there is unreferenced with dbus_connection_unref().445*446* For example, this function and the similar functions for447* other reference-counted types can be used in code like this:448*449* @code450* DBusConnection *conn = NULL;451* struct { ...; DBusMessage *m; ... } *larger_structure = ...;452*453* ... code that might set conn or m to be non-NULL ...454*455* dbus_clear_connection (&conn);456* dbus_clear_message (&larger_structure->m);457* @endcode458*459* @param pointer_to_connection A pointer to a variable or struct member.460* pointer_to_connection must not be #NULL, but *pointer_to_connection461* may be #NULL.462*/463static inline void464dbus_clear_connection (DBusConnection **pointer_to_connection)465{466_dbus_clear_pointer_impl (DBusConnection, pointer_to_connection,467dbus_connection_unref);468}469470/** @} */471472473/**474* @addtogroup DBusWatch475* @{476*/477478#ifndef DBUS_DISABLE_DEPRECATED479DBUS_EXPORT480DBUS_DEPRECATED int dbus_watch_get_fd (DBusWatch *watch);481#endif482483DBUS_EXPORT484int dbus_watch_get_unix_fd (DBusWatch *watch);485DBUS_EXPORT486int dbus_watch_get_socket (DBusWatch *watch);487DBUS_EXPORT488unsigned int dbus_watch_get_flags (DBusWatch *watch);489DBUS_EXPORT490void* dbus_watch_get_data (DBusWatch *watch);491DBUS_EXPORT492void dbus_watch_set_data (DBusWatch *watch,493void *data,494DBusFreeFunction free_data_function);495DBUS_EXPORT496dbus_bool_t dbus_watch_handle (DBusWatch *watch,497unsigned int flags);498DBUS_EXPORT499dbus_bool_t dbus_watch_get_enabled (DBusWatch *watch);500501/** @} */502503/**504* @addtogroup DBusTimeout505* @{506*/507508DBUS_EXPORT509int dbus_timeout_get_interval (DBusTimeout *timeout);510DBUS_EXPORT511void* dbus_timeout_get_data (DBusTimeout *timeout);512DBUS_EXPORT513void dbus_timeout_set_data (DBusTimeout *timeout,514void *data,515DBusFreeFunction free_data_function);516DBUS_EXPORT517dbus_bool_t dbus_timeout_handle (DBusTimeout *timeout);518DBUS_EXPORT519dbus_bool_t dbus_timeout_get_enabled (DBusTimeout *timeout);520521/** @} */522523DBUS_END_DECLS524525#endif /* DBUS_CONNECTION_H */526527528