本文整理汇总了C++中dbus_watch_get_unix_fd函数的典型用法代码示例。如果您正苦于以下问题:C++ dbus_watch_get_unix_fd函数的具体用法?C++ dbus_watch_get_unix_fd怎么用?C++ dbus_watch_get_unix_fd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dbus_watch_get_unix_fd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_watch
static dbus_bool_t add_watch(DBusWatch *watch, void *data)
{
GIOCondition cond = G_IO_HUP | G_IO_ERR;
DBusConnection *conn = data;
struct watch_info *info;
int fd, flags;
if (!dbus_watch_get_enabled(watch))
return TRUE;
info = g_new(struct watch_info, 1);
fd = dbus_watch_get_unix_fd(watch);
info->io = g_io_channel_unix_new(fd);
info->conn = dbus_connection_ref(conn);
dbus_watch_set_data(watch, info, NULL);
flags = dbus_watch_get_flags(watch);
if (flags & DBUS_WATCH_READABLE) cond |= G_IO_IN;
if (flags & DBUS_WATCH_WRITABLE) cond |= G_IO_OUT;
info->watch_id = g_io_add_watch(info->io, cond, watch_func, watch);
return TRUE;
}
示例2: AddWatch
static dbus_bool_t
AddWatch(DBusWatch *aWatch, void *aData)
{
DBusThread *dbt = (DBusThread *)aData;
if (dbus_watch_get_enabled(aWatch)) {
// note that we can't just send the watch and inspect it later
// because we may get a removeWatch call before this data is reacted
// to by our eventloop and remove this watch.. reading the add first
// and then inspecting the recently deceased watch would be bad.
char control = DBUS_EVENT_LOOP_ADD;
if (write(dbt->mControlFdW.get(), &control, sizeof(char)) < 0) {
LOG("Cannot write DBus add watch control data to socket!\n");
return false;
}
int fd = dbus_watch_get_unix_fd(aWatch);
if (write(dbt->mControlFdW.get(), &fd, sizeof(int)) < 0) {
LOG("Cannot write DBus add watch descriptor data to socket!\n");
return false;
}
unsigned int flags = dbus_watch_get_flags(aWatch);
if (write(dbt->mControlFdW.get(), &flags, sizeof(unsigned int)) < 0) {
LOG("Cannot write DBus add watch flag data to socket!\n");
return false;
}
if (write(dbt->mControlFdW.get(), &aWatch, sizeof(DBusWatch*)) < 0) {
LOG("Cannot write DBus add watch struct data to socket!\n");
return false;
}
}
return true;
}
示例3: add_watch
static dbus_bool_t add_watch(DBusWatch *w, void *data)
{
if (!dbus_watch_get_enabled(w))
return TRUE;
ASDBusFd *fd = safecalloc (1, sizeof(ASDBusFd));
fd->fd = dbus_watch_get_unix_fd(w);
unsigned int flags = dbus_watch_get_flags(w);
if (get_flags(flags, DBUS_WATCH_READABLE))
fd->readable = True;
/*short cond = EV_PERSIST;
if (flags & DBUS_WATCH_READABLE)
cond |= EV_READ;
if (flags & DBUS_WATCH_WRITABLE)
cond |= EV_WRITE; */
// TODO add to the list of FDs
dbus_watch_set_data(w, fd, NULL);
if (ASDBus.watchFds == NULL)
ASDBus.watchFds = create_asvector (sizeof(ASDBusFd*));
append_vector(ASDBus.watchFds, &fd, 1);
show_debug(__FILE__,__FUNCTION__,__LINE__,"added dbus watch fd=%d watch=%p readable =%d\n", fd->fd, w, fd->readable);
return TRUE;
}
示例4: addWatch
static dbus_bool_t addWatch(DBusWatch *watch, void *data)
{
dbus_bool_t result = FALSE;
(void)data;
if (ARRAY_SIZE(gPollInfo.fds) > (unsigned int)(gPollInfo.nfds))
{
unsigned int flags = dbus_watch_get_flags(watch);
tObjectEntry * const pEntry = &gPollInfo.objects[gPollInfo.nfds];
pEntry->objtype = OT_WATCH;
pEntry->watch = watch;
gPollInfo.fds[gPollInfo.nfds].fd = dbus_watch_get_unix_fd(watch);
if (TRUE==dbus_watch_get_enabled(watch))
{
if (flags&DBUS_WATCH_READABLE)
{
gPollInfo.fds[gPollInfo.nfds].events |= POLLIN;
}
if (flags&DBUS_WATCH_WRITABLE)
{
gPollInfo.fds[gPollInfo.nfds].events |= POLLOUT;
}
++gPollInfo.nfds;
}
result = TRUE;
}
return result;
}
示例5: GetPollFds
/**
* GetPollFds() fills an array of pollfd data structures with :
* - the set of enabled dbus watches
* - the unix pipe which we use to manually wake up the main loop
*
* This function must be called with p_sys->lock locked
*
* @return The number of file descriptors
*
* @param intf_thread_t *p_intf this interface thread's state
* @param struct pollfd *p_fds a pointer to a pollfd array large enough to
* contain all the returned data (number of enabled dbus watches + 1)
*/
static int GetPollFds( intf_thread_t *p_intf, struct pollfd *p_fds )
{
intf_sys_t *p_sys = p_intf->p_sys;
int i_fds = 1, i_watches = vlc_array_count( p_sys->p_watches );
p_fds[0].fd = p_sys->p_pipe_fds[PIPE_OUT];
p_fds[0].events = POLLIN | POLLPRI;
for( int i = 0; i < i_watches; i++ )
{
DBusWatch *p_watch = NULL;
p_watch = vlc_array_item_at_index( p_sys->p_watches, i );
if( !dbus_watch_get_enabled( p_watch ) )
continue;
p_fds[i_fds].fd = dbus_watch_get_unix_fd( p_watch );
int i_flags = dbus_watch_get_flags( p_watch );
if( i_flags & DBUS_WATCH_READABLE )
p_fds[i_fds].events |= POLLIN | POLLPRI;
if( i_flags & DBUS_WATCH_WRITABLE )
p_fds[i_fds].events |= POLLOUT;
i_fds++;
}
return i_fds;
}
示例6: TEMP_FAILURE_RETRY
void
DBusWatcher::RemoveWatch(DBusWatch* aWatch)
{
static const char control = DBUS_EVENT_LOOP_REMOVE;
ssize_t res =
TEMP_FAILURE_RETRY(write(mControlFdW.get(), &control, sizeof(control)));
if (res < 0) {
LOG("Cannot write DBus remove watch control data to socket!\n");
return;
}
int fd = dbus_watch_get_unix_fd(aWatch);
res = TEMP_FAILURE_RETRY(write(mControlFdW.get(), &fd, sizeof(fd)));
if (res < 0) {
LOG("Cannot write DBus remove watch descriptor data to socket!\n");
return;
}
unsigned int flags = dbus_watch_get_flags(aWatch);
res = TEMP_FAILURE_RETRY(write(mControlFdW.get(), &flags, sizeof(flags)));
if (res < 0) {
LOG("Cannot write DBus remove watch flag data to socket!\n");
return;
}
}
示例7: check_dbus_listeners
void check_dbus_listeners(fd_set *rset, fd_set *wset, fd_set *eset)
{
DBusConnection *connection = (DBusConnection *)daemon->dbus;
struct watch *w;
for (w = daemon->watches; w; w = w->next)
if (dbus_watch_get_enabled(w->watch))
{
unsigned int flags = 0;
int fd = dbus_watch_get_unix_fd(w->watch);
if (FD_ISSET(fd, rset))
flags |= DBUS_WATCH_READABLE;
if (FD_ISSET(fd, wset))
flags |= DBUS_WATCH_WRITABLE;
if (FD_ISSET(fd, eset))
flags |= DBUS_WATCH_ERROR;
if (flags != 0)
dbus_watch_handle(w->watch, flags);
}
if (connection)
{
dbus_connection_ref (connection);
while (dbus_connection_dispatch (connection) == DBUS_DISPATCH_DATA_REMAINS);
dbus_connection_unref (connection);
}
}
示例8: virDBusAddWatch
static dbus_bool_t virDBusAddWatch(DBusWatch *watch,
void *data)
{
int flags = 0;
int fd;
struct virDBusWatch *info;
if (VIR_ALLOC(info) < 0)
return 0;
if (dbus_watch_get_enabled(watch))
flags = virDBusTranslateWatchFlags(dbus_watch_get_flags(watch));
# if HAVE_DBUS_WATCH_GET_UNIX_FD
fd = dbus_watch_get_unix_fd(watch);
# else
fd = dbus_watch_get_fd(watch);
# endif
info->bus = (DBusConnection *)data;
info->watch = virEventAddHandle(fd, flags,
virDBusWatchCallback,
watch, NULL);
if (info->watch < 0) {
VIR_FREE(info);
return 0;
}
dbus_watch_set_data(watch, info, virDBusWatchFree);
return 1;
}
示例9: handle_io_event
/* pa_io_event_cb_t IO event handler */
static void handle_io_event(pa_mainloop_api *ea, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata) {
unsigned int flags = 0;
DBusWatch *watch = userdata;
#if HAVE_DBUS_WATCH_GET_UNIX_FD
pa_assert(fd == dbus_watch_get_unix_fd(watch));
#else
pa_assert(fd == dbus_watch_get_fd(watch));
#endif
if (!dbus_watch_get_enabled(watch)) {
pa_log_warn("Asked to handle disabled watch: %p %i", (void*) watch, fd);
return;
}
if (events & PA_IO_EVENT_INPUT)
flags |= DBUS_WATCH_READABLE;
if (events & PA_IO_EVENT_OUTPUT)
flags |= DBUS_WATCH_WRITABLE;
if (events & PA_IO_EVENT_HANGUP)
flags |= DBUS_WATCH_HANGUP;
if (events & PA_IO_EVENT_ERROR)
flags |= DBUS_WATCH_ERROR;
dbus_watch_handle(watch, flags);
}
示例10: dbus_watch_get_fd
/**
* Deprecated former name of dbus_watch_get_unix_fd().
*
* @param watch the DBusWatch object.
* @returns the file descriptor to watch.
*/
int
dbus_watch_get_fd (DBusWatch *watch)
{
_dbus_return_val_if_fail (watch != NULL, -1);
return dbus_watch_get_unix_fd(watch);
}
示例11: sbus_add_watch
/*
* add_watch
* Set up hooks into the libevents mainloop for
* D-BUS to add file descriptor-based events
*/
dbus_bool_t sbus_add_watch(DBusWatch *dbus_watch, void *data)
{
unsigned int flags;
uint16_t event_flags;
struct sbus_connection *conn;
struct sbus_watch_ctx *watch;
dbus_bool_t enabled;
int fd;
conn = talloc_get_type(data, struct sbus_connection);
#ifdef HAVE_DBUS_WATCH_GET_UNIX_FD
fd = dbus_watch_get_unix_fd(dbus_watch);
#else
fd = dbus_watch_get_fd(dbus_watch);
#endif
watch = fd_to_watch(conn->watch_list, fd);
if (!watch) {
/* does not exist, allocate new one */
watch = talloc_zero(conn, struct sbus_watch_ctx);
if (!watch) {
DEBUG(0, ("Out of Memory!\n"));
return FALSE;
}
watch->conn = conn;
watch->fd = fd;
}
示例12: dbus_watch_get_flags
//Callbacks implementation
unsigned int DBusHandler::Callbacks::addWatch(DBusWatch* watch, void* data)
{
if(!data) return 0;
auto& loop = static_cast<DBusHandler*>(data)->compositor().wlEventLoop();
unsigned int mask = 0;
if (dbus_watch_get_enabled(watch))
{
unsigned int flags = dbus_watch_get_flags(watch);
if (flags & DBUS_WATCH_READABLE) mask |= WL_EVENT_READABLE;
if (flags & DBUS_WATCH_WRITABLE) mask |= WL_EVENT_WRITABLE;
}
int fd = dbus_watch_get_unix_fd(watch);
wl_event_source* source = wl_event_loop_add_fd(&loop, fd, mask, dispatchWatch, watch);
if (!source)
{
ny::sendWarning("failed to add dbus watch wl_event_loop_fd");
return 0;
}
dbus_watch_set_data(watch, source, nullptr);
return 1;
}
示例13: get_pollfds
static int get_pollfds(struct dbus* dbus, struct pollfd *pollfds)
{
int count = 0;
Word_t index = 0;
DBusWatch** pwatch;
JLF(pwatch, dbus->watches, index);
while(pwatch != NULL) {
DBusWatch* watch = *pwatch;
if(dbus_watch_get_enabled(watch)) {
pollfds[count].fd = dbus_watch_get_unix_fd(watch);
pollfds[count].events = 0;
int flags = dbus_watch_get_flags(watch);
if(flags & DBUS_WATCH_READABLE) pollfds[count].events |= POLLIN | POLLPRI;
if(flags & DBUS_WATCH_WRITABLE) pollfds[count].events |= POLLOUT;
count += 1;
}
JLN(pwatch, dbus->watches, index);
}
return count;
}
示例14: cdbus_callback_remove_watch
/**
* Callback for removing D-Bus watch.
*/
static void
cdbus_callback_remove_watch(DBusWatch *watch, void *data) {
session_t *ps = data;
fds_drop(ps, dbus_watch_get_unix_fd(watch),
cdbus_get_watch_cond(watch));
}
示例15: connection_setup_add_watch
static void connection_setup_add_watch(struct ctrl_iface_dbus_priv *iface,
DBusWatch *watch)
{
unsigned int flags;
int fd;
if (!dbus_watch_get_enabled(watch))
return;
flags = dbus_watch_get_flags(watch);
fd = dbus_watch_get_unix_fd(watch);
eloop_register_sock(fd, EVENT_TYPE_EXCEPTION, process_watch_exception,
iface, watch);
if (flags & DBUS_WATCH_READABLE) {
eloop_register_sock(fd, EVENT_TYPE_READ, process_watch_read,
iface, watch);
}
if (flags & DBUS_WATCH_WRITABLE) {
eloop_register_sock(fd, EVENT_TYPE_WRITE, process_watch_write,
iface, watch);
}
dbus_watch_set_data(watch, iface, NULL);
}