phStatus_t phOsal_GLib_Timer_Start( phOsal_GLib_DataParams_t *pDataParams, uint32_t dwTimerId, uint32_t dwRegTimeCnt, uint16_t wOption, ppCallBck_t pApplicationCallback, void *pContext ) { //g_debug("Starting timer %d...\r\n", dwTimerId); if( (dwTimerId > OSAL_GLIB_MAX_TIMERS) || (pDataParams->gTimers[dwTimerId].bTimerFree == TIMER_FREE) ) { /* Can't use a non existent timer */ /* Can't start a free timer, first create the timer */ return PH_ADD_COMPCODE(PH_ERR_INTERNAL_ERROR, PH_COMP_OSAL); } if( pDataParams->gTimers[dwTimerId].pGTimeoutSource != NULL ) { //Cannot start at timer which is already running g_error("Timer %d already running\n", dwTimerId); return PH_ADD_COMPCODE(PH_ERR_INTERNAL_ERROR, PH_COMP_OSAL); } //Convert usecs to millisecs if needed if( wOption == 0 ) // { //g_debug("%d us", dwRegTimeCnt); //We're running in user-mode on a (probably) non realtime kernel, so even millisecs are very approximate if( dwRegTimeCnt < 1000 ) { pDataParams->gTimers[dwTimerId].dwMillisecs = 1; } else { pDataParams->gTimers[dwTimerId].dwMillisecs = dwRegTimeCnt / 1000; } } else //These are already millisecs { //g_debug("%d ms", dwRegTimeCnt); pDataParams->gTimers[dwTimerId].dwMillisecs = dwRegTimeCnt; } //Remember callback pDataParams->gTimers[dwTimerId].pApplicationCallback = pApplicationCallback; pDataParams->gTimers[dwTimerId].pContext = pContext; //Create source pDataParams->gTimers[dwTimerId].pGTimeoutSource = g_timeout_source_new(pDataParams->gTimers[dwTimerId].dwMillisecs); if( pDataParams->gTimers[dwTimerId].pGTimeoutSource == NULL) { return PH_ADD_COMPCODE(PH_ERR_INSUFFICIENT_RESOURCES, PH_COMP_OSAL); } //Set callback g_source_set_callback(pDataParams->gTimers[dwTimerId].pGTimeoutSource, phOsal_Int_Timer_Callback, &pDataParams->gTimers[dwTimerId], NULL); //Attach source to context g_source_attach(pDataParams->gTimers[dwTimerId].pGTimeoutSource, pDataParams->pgGLibMainContext); return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_OSAL); }
static gboolean gui_pdb_dialog_new (Gimp *gimp, GimpContext *context, GimpProgress *progress, GimpContainer *container, const gchar *title, const gchar *callback_name, const gchar *object_name, va_list args) { GType dialog_type = G_TYPE_NONE; const gchar *dialog_role = NULL; const gchar *help_id = NULL; if (gimp_container_get_children_type (container) == GIMP_TYPE_BRUSH) { dialog_type = GIMP_TYPE_BRUSH_SELECT; dialog_role = "gimp-brush-selection"; help_id = GIMP_HELP_BRUSH_DIALOG; } else if (gimp_container_get_children_type (container) == GIMP_TYPE_FONT) { dialog_type = GIMP_TYPE_FONT_SELECT; dialog_role = "gimp-font-selection"; help_id = GIMP_HELP_FONT_DIALOG; } else if (gimp_container_get_children_type (container) == GIMP_TYPE_GRADIENT) { dialog_type = GIMP_TYPE_GRADIENT_SELECT; dialog_role = "gimp-gradient-selection"; help_id = GIMP_HELP_GRADIENT_DIALOG; } else if (gimp_container_get_children_type (container) == GIMP_TYPE_PALETTE) { dialog_type = GIMP_TYPE_PALETTE_SELECT; dialog_role = "gimp-palette-selection"; help_id = GIMP_HELP_PALETTE_DIALOG; } else if (gimp_container_get_children_type (container) == GIMP_TYPE_PATTERN) { dialog_type = GIMP_TYPE_PATTERN_SELECT; dialog_role = "gimp-pattern-selection"; help_id = GIMP_HELP_PATTERN_DIALOG; } if (dialog_type != G_TYPE_NONE) { GimpObject *object = NULL; if (object_name && strlen (object_name)) object = gimp_container_get_child_by_name (container, object_name); if (! object) object = gimp_context_get_by_type (context, gimp_container_get_children_type (container)); if (object) { GParameter *params = NULL; gint n_params = 0; GtkWidget *dialog; GtkWidget *view; params = gimp_parameters_append (dialog_type, params, &n_params, "title", title, "role", dialog_role, "help-func", gimp_standard_help_func, "help-id", help_id, "pdb", gimp->pdb, "context", context, "select-type", gimp_container_get_children_type (container), "initial-object", object, "callback-name", callback_name, "menu-factory", global_menu_factory, NULL); params = gimp_parameters_append_valist (dialog_type, params, &n_params, args); dialog = g_object_newv (dialog_type, n_params, params); gimp_parameters_free (params, n_params); view = GIMP_PDB_DIALOG (dialog)->view; if (view) gimp_docked_set_show_button_bar (GIMP_DOCKED (view), FALSE); if (progress) { guint32 window_id = gimp_progress_get_window_id (progress); if (window_id) gimp_window_set_transient_for (GTK_WINDOW (dialog), window_id); } gtk_widget_show (dialog); /* workaround for bug #360106 */ { GSource *source = g_timeout_source_new (100); GClosure *closure; closure = g_cclosure_new_object (G_CALLBACK (gui_pdb_dialog_present), G_OBJECT (dialog)); g_source_set_closure (source, closure); g_source_attach (source, NULL); g_source_unref (source); } return TRUE; } } return FALSE; }
/** @girskip * Adds a GLib main loop timeout callback that will be removed when unloading the plugin, * preventing it to run after the plugin has been unloaded (which may lead to a segfault). * * @param plugin Must be @ref geany_plugin. * @param interval The time between calls to the function, in milliseconds. * @param function The function to call after the given timeout. * @param data The user data passed to the function. * @return the ID of the event source (you generally won't need it, or better use g_timeout_add() * directly if you want to manage this event source manually). * * @see g_timeout_add() * @since 0.21, plugin API 205. */ GEANY_API_SYMBOL guint plugin_timeout_add(GeanyPlugin *plugin, guint interval, GSourceFunc function, gpointer data) { return plugin_source_add(plugin, g_timeout_source_new(interval), function, data); }
while(msg_list){ Message* message = g_list_first(msg_list)->data; msg_list = g_list_remove(msg_list, message); Sample* sample = message->sample; message->work(sample, message->user_data); g_idle_add(done, message); g_usleep(1000); // may possibly help prevent tree freezes if too many jobs complete in quick succession. } return G_SOURCE_CONTINUE; } GMainContext* context = g_main_context_new(); GSource* source = g_timeout_source_new(1000); gpointer _data = NULL; g_source_set_callback(source, worker_timeout, _data, NULL); g_source_attach(source, context); g_main_loop_run (g_main_loop_new (context, 0)); return NULL; } void worker_add_job(Sample* sample, SampleCallback work, SampleCallback done, gpointer user_data) { if(!msg_queue) return;
gboolean ToolsDaemonTcloSyncDriverFreeze(RpcInData *data) { static char resultBuffer[DEFAULT_RESULT_MSG_MAX_LENGTH]; VixError err = VIX_OK; char *driveList = NULL; char *timeout = NULL; int timeoutVal; DECLARE_SYNCDRIVER_ERROR(sysError); ToolsAppCtx *ctx = data->appCtx; GSource *timer; Debug(">ToolsDaemonTcloSyncDriverFreeze\n"); /* * Parse the arguments */ driveList = ToolsDaemonTcloGetQuotedString(data->args, &data->args); timeout = ToolsDaemonTcloGetQuotedString(data->args, &data->args); /* * Validate the arguments. */ if (NULL == driveList || NULL == timeout) { err = VIX_E_INVALID_ARG; Debug("ToolsDaemonTcloSyncDriverFreeze: Failed to get string args\n"); goto abort; } if (!StrUtil_StrToInt(&timeoutVal, timeout) || timeoutVal < 0) { Debug("ToolsDaemonTcloSyncDriverFreeze: Bad args, timeout '%s'\n", timeout); err = VIX_E_INVALID_ARG; goto abort; } Debug("SYNCDRIVE: Got request to freeze '%s', timeout %d\n", driveList, timeoutVal); /* Disallow multiple freeze calls. */ if (gSyncDriverHandle != SYNCDRIVER_INVALID_HANDLE) { err = VIX_E_OBJECT_IS_BUSY; goto abort; } /* Perform the actual freeze. */ if (!SyncDriver_Freeze(driveList, &gSyncDriverHandle) || SyncDriver_QueryStatus(gSyncDriverHandle, INFINITE) != SYNCDRIVER_IDLE) { Debug("ToolsDaemonTcloSyncDriverFreeze: Failed to Freeze drives '%s'\n", driveList); err = VIX_E_FAIL; sysError = SYNCDRIVERERROR; if (gSyncDriverHandle != SYNCDRIVER_INVALID_HANDLE) { SyncDriver_Thaw(gSyncDriverHandle); SyncDriver_CloseHandle(&gSyncDriverHandle); } goto abort; } /* Start the timer callback to automatically thaw. */ if (0 != timeoutVal) { Debug("ToolsDaemonTcloSyncDriverFreeze: Starting timer callback %d\n", timeoutVal); timer = g_timeout_source_new(timeoutVal * 10); VMTOOLSAPP_ATTACH_SOURCE(ctx, timer, ToolsDaemonSyncDriverThawCallback, NULL, NULL); g_source_unref(timer); } abort: /* * These were allocated by ToolsDaemonTcloGetQuotedString. */ free(driveList); free(timeout); /* * All Foundry tools commands return results that start with a * foundry error and a guest-OS-specific error. */ Str_Sprintf(resultBuffer, sizeof resultBuffer, "%"FMT64"d %d", err, sysError); Debug("<ToolsDaemonTcloSyncDriverFreeze\n"); return RPCIN_SETRETVALS(data, resultBuffer, TRUE); }
/* program main */ int main() { char* tmsg = NULL; int main_tmo = 5; int loop1_tmo = 2 * main_tmo; int loop2_tmo = 3; twmsg(__func__, "STARTING"); /* setup the main loop structure */ tmsg=g_strdup_printf("creating main context, TMO=%d", main_tmo); twmsg(__func__, tmsg); g_free(tmsg); loop_main.name = g_strdup("MAIN"); loop_main.tmo = main_tmo; /* seconds for callback */ loop_main.main_context = NULL; /* use default */ loop_main.main_loop = g_main_loop_new (loop_main.main_context, FALSE); loop_main.idle = g_idle_source_new(); g_source_set_callback(loop_main.idle, idle_func, &loop_main, NULL); g_source_attach(loop_main.idle, loop_main.main_context); loop_main.main_context = NULL; /* use default */ loop_main.Q = NULL; /* no queue, for now */ loop_main.TH = NULL; /* this is the main thread so no thread info */ /* interval, function callback, userdata * - internally creates source and attaches to main context */ g_timeout_add_seconds(loop_main.tmo, tmo_callback, "tmo_callback"); /* create info for the worker thread and set up its context, then run it */ tmsg=g_strdup_printf("creating loop1 context, TMO=%d", loop1_tmo); twmsg(__func__, tmsg); g_free(tmsg); loop_main.name = g_strdup("LOOP_1"); loop_1.tmo = loop1_tmo; loop_1.main_context = g_main_context_new(); loop_1.main_loop = g_main_loop_new(loop_1.main_context, FALSE); loop_1.idle = g_idle_source_new(); g_source_set_callback(loop_1.idle, idle_func, &loop_1, NULL); g_source_attach(loop_1.idle, loop_1.main_context); loop_1.Q = g_async_queue_new(); /* manually create new timeout source and attach to main context of nth Loop * - timeout is in ms so multiply seconds by 1000 * - set priority to 1 or 2 * - optionally set name */ GSource *source1 = g_timeout_source_new (loop_1.tmo*1000); g_source_set_priority (source1, 1); g_source_set_callback (source1, tmo_callback, "tmo_loop1_callback", NULL); g_source_set_name (source1, "LOOP1_TMO"); g_source_attach (source1, loop_1.main_context); /* run the thread which will run the main context */ loop_1.TH = g_thread_new("LOOP1_TH", loop_thread, &loop_1); /* create info for the second worker thread and set up its context, then run it */ tmsg=g_strdup_printf("creating loop2 context, TMO=%d", loop2_tmo); twmsg(__func__, tmsg); g_free(tmsg); /* init the data for the context */ loop_2.name = g_strdup("LOOP_2"); loop_2.tmo = loop2_tmo; loop_2.main_context = g_main_context_new(); loop_2.main_loop = g_main_loop_new(loop_2.main_context, FALSE); loop_2.idle = g_idle_source_new(); g_source_set_callback(loop_2.idle, idle_func, &loop_2, NULL); g_source_attach(loop_2.idle, loop_2.main_context); loop_2.Q = g_async_queue_new(); /* manually create new timeout source and attach to main context of nth Loop * - timeout is in ms so multiply seconds by 1000 * - set priority to 1 or 2 * - optionally set name */ GSource *source2 = g_timeout_source_new (loop_2.tmo*1000); g_source_set_priority (source2, 1); g_source_set_callback (source2, tmo_callback, "tmo_loop2_callback", NULL); g_source_set_name (source2, "LOOP2_TMO"); g_source_attach (source2, loop_2.main_context); /* run the second thread */ loop_2.TH = g_thread_new("LOOP2_TH", loop_thread, &loop_2); /* run the main loop */ g_main_loop_run(loop_main.main_loop); return 0; }
/* * Received a message */ static void message_received_cb (G_GNUC_UNUSED GSSDPClient *client, const char *from_ip, gushort from_port, _GSSDPMessageType type, SoupMessageHeaders *headers, gpointer user_data) { GSSDPResourceGroup *resource_group; GSSDPResourceGroupPrivate *priv; const char *target, *mx_str, *version_str, *man; gboolean want_all; int mx, version; GList *l; resource_group = GSSDP_RESOURCE_GROUP (user_data); priv = gssdp_resource_group_get_instance_private (resource_group); /* Only process if we are available */ if (!priv->available) return; /* We only handle discovery requests */ if (type != _GSSDP_DISCOVERY_REQUEST) return; /* Extract target */ target = soup_message_headers_get_one (headers, "ST"); if (target == NULL) { g_warning ("Discovery request did not have an ST header"); return; } /* Is this the "ssdp:all" target? */ want_all = (strcmp (target, GSSDP_ALL_RESOURCES) == 0); /* Extract MX */ mx_str = soup_message_headers_get_one (headers, "MX"); if (mx_str == NULL || atoi (mx_str) <= 0) { g_warning ("Discovery request did not have a valid MX header"); return; } man = soup_message_headers_get_one (headers, "MAN"); if (man == NULL || strcmp (man, DEFAULT_MAN_HEADER) != 0) { g_warning ("Discovery request did not have a valid MAN header"); return; } mx = atoi (mx_str); /* Extract version */ version_str = get_version_for_target ((char *) target); if (version_str != NULL) version = atoi (version_str); else version = 0; /* Find matching resource */ for (l = priv->resources; l != NULL; l = l->next) { Resource *resource; resource = l->data; if (want_all || (g_regex_match (resource->target_regex, target, 0, NULL) && (guint) version <= resource->version)) { /* Match. */ guint timeout; DiscoveryResponse *response; /* Get a random timeout from the interval [0, mx] */ timeout = g_random_int_range (0, mx * 1000); /* Prepare response */ response = g_slice_new (DiscoveryResponse); response->dest_ip = g_strdup (from_ip); response->dest_port = from_port; response->resource = resource; if (want_all) response->target = g_strdup (resource->target); else response->target = g_strdup (target); /* Add timeout */ response->timeout_src = g_timeout_source_new (timeout); g_source_set_callback (response->timeout_src, discovery_response_timeout, response, NULL); g_source_attach (response->timeout_src, g_main_context_get_thread_default ()); g_source_unref (response->timeout_src); /* Add to resource */ resource->responses = g_list_prepend (resource->responses, response); } } }
/** * gst_video_convert_sample_async: * @sample: a #GstSample * @to_caps: the #GstCaps to convert to * @timeout: the maximum amount of time allowed for the processing. * @callback: %GstVideoConvertSampleCallback that will be called after conversion. * @user_data: extra data that will be passed to the @callback * @destroy_notify: %GDestroyNotify to be called after @user_data is not needed anymore * * Converts a raw video buffer into the specified output caps. * * The output caps can be any raw video formats or any image formats (jpeg, png, ...). * * The width, height and pixel-aspect-ratio can also be specified in the output caps. * * @callback will be called after conversion, when an error occured or if conversion didn't * finish after @timeout. @callback will always be called from the thread default * %GMainContext, see g_main_context_get_thread_default(). If GLib before 2.22 is used, * this will always be the global default main context. * * @destroy_notify will be called after the callback was called and @user_data is not needed * anymore. */ void gst_video_convert_sample_async (GstSample * sample, const GstCaps * to_caps, GstClockTime timeout, GstVideoConvertSampleCallback callback, gpointer user_data, GDestroyNotify destroy_notify) { GMainContext *context = NULL; GError *error = NULL; GstBus *bus; GstBuffer *buf; GstCaps *from_caps, *to_caps_copy = NULL; GstElement *pipeline, *src, *sink; guint i, n; GSource *source; GstVideoConvertSampleContext *ctx; g_return_if_fail (sample != NULL); buf = gst_sample_get_buffer (sample); g_return_if_fail (buf != NULL); g_return_if_fail (to_caps != NULL); from_caps = gst_sample_get_caps (sample); g_return_if_fail (from_caps != NULL); g_return_if_fail (callback != NULL); context = g_main_context_get_thread_default (); if (!context) context = g_main_context_default (); to_caps_copy = gst_caps_new_empty (); n = gst_caps_get_size (to_caps); for (i = 0; i < n; i++) { GstStructure *s = gst_caps_get_structure (to_caps, i); s = gst_structure_copy (s); gst_structure_remove_field (s, "framerate"); gst_caps_append_structure (to_caps_copy, s); } pipeline = build_convert_frame_pipeline (&src, &sink, from_caps, gst_buffer_get_video_crop_meta (buf), to_caps_copy, &error); if (!pipeline) goto no_pipeline; bus = gst_element_get_bus (pipeline); ctx = g_slice_new0 (GstVideoConvertSampleContext); g_mutex_init (&ctx->mutex); //ctx->buffer = gst_buffer_ref (buf); ctx->sample = gst_sample_ref (sample); ctx->callback = callback; ctx->user_data = user_data; ctx->destroy_notify = destroy_notify; ctx->context = g_main_context_ref (context); ctx->finished = FALSE; ctx->pipeline = pipeline; if (timeout != GST_CLOCK_TIME_NONE) { ctx->timeout_source = g_timeout_source_new (timeout / GST_MSECOND); g_source_set_callback (ctx->timeout_source, (GSourceFunc) convert_frame_timeout_callback, ctx, NULL); g_source_attach (ctx->timeout_source, context); } g_signal_connect (src, "need-data", G_CALLBACK (convert_frame_need_data_callback), ctx); g_signal_connect (sink, "new-preroll", G_CALLBACK (convert_frame_new_preroll_callback), ctx); source = gst_bus_create_watch (bus); g_source_set_callback (source, (GSourceFunc) convert_frame_bus_callback, ctx, NULL); g_source_attach (source, context); g_source_unref (source); gst_element_set_state (pipeline, GST_STATE_PLAYING); gst_object_unref (bus); gst_caps_unref (to_caps_copy); return; /* ERRORS */ no_pipeline: { GstVideoConvertSampleCallbackContext *ctx; GSource *source; gst_caps_unref (to_caps_copy); ctx = g_slice_new0 (GstVideoConvertSampleCallbackContext); ctx->callback = callback; ctx->user_data = user_data; ctx->destroy_notify = destroy_notify; ctx->sample = NULL; ctx->error = error; source = g_timeout_source_new (0); g_source_set_callback (source, (GSourceFunc) convert_frame_dispatch_callback, ctx, (GDestroyNotify) gst_video_convert_frame_callback_context_free); g_source_attach (source, context); g_source_unref (source); } }
static void * glib_ctx_add(void *ctx, const verto_ev *ev, verto_ev_flag *flags) { glib_ev *gev = NULL; GIOCondition cond = 0; verto_ev_type type = verto_get_type(ev); gev = g_new0(glib_ev, 1); if (!gev) return NULL; switch (type) { case VERTO_EV_TYPE_IO: #ifdef WIN32 gev->chan = g_io_channel_win32_new_socket(verto_get_fd(ev)); #else gev->chan = g_io_channel_unix_new(verto_get_fd(ev)); #endif if (!gev->chan) goto error; g_io_channel_set_close_on_unref(gev->chan, FALSE); if (*flags & VERTO_EV_FLAG_IO_READ) cond |= G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL; if (*flags & VERTO_EV_FLAG_IO_WRITE) cond |= G_IO_OUT | G_IO_ERR | G_IO_HUP | G_IO_NVAL; gev->src = g_io_create_watch(gev->chan, cond); break; case VERTO_EV_TYPE_TIMEOUT: gev->src = g_timeout_source_new(verto_get_interval(ev)); break; case VERTO_EV_TYPE_IDLE: gev->src = g_idle_source_new(); break; case VERTO_EV_TYPE_CHILD: gev->src = g_child_watch_source_new(verto_get_proc(ev)); *flags &= ~VERTO_EV_FLAG_PERSIST; /* Child events don't persist */ break; case VERTO_EV_TYPE_SIGNAL: #if GLIB_MAJOR_VERSION >= 2 #if GLIB_MINOR_VERSION >= 29 #ifdef G_OS_UNIX /* Not supported on Windows */ gev->src = g_unix_signal_source_new(verto_get_signal(ev)); break; #endif #endif /* GLIB_MINOR_VERSION >= 29 */ #endif /* GLIB_MAJOR_VERSION >= 2 */ default: return NULL; /* Not supported */ } if (!gev->src) goto error; if (type == VERTO_EV_TYPE_IO) g_source_set_callback(gev->src, (GSourceFunc) glib_callback_io, (void *) ev, NULL); else if (type == VERTO_EV_TYPE_CHILD) g_source_set_callback(gev->src, (GSourceFunc) glib_callback_child, (void *) ev, NULL); else g_source_set_callback(gev->src, glib_callback, (void *) ev, NULL); if (*flags & VERTO_EV_FLAG_PRIORITY_HIGH) g_source_set_priority(gev->src, G_PRIORITY_HIGH); else if (*flags & VERTO_EV_FLAG_PRIORITY_MEDIUM) g_source_set_priority(gev->src, G_PRIORITY_DEFAULT_IDLE); else if (*flags & VERTO_EV_FLAG_PRIORITY_LOW) g_source_set_priority(gev->src, G_PRIORITY_LOW); g_source_set_can_recurse(gev->src, FALSE); if (g_source_attach(gev->src, ((glib_ev_ctx*) ctx)->context) == 0) goto error; return gev; error: if (gev) { if (gev->chan) g_io_channel_unref(gev->chan); if (gev->src) { g_source_destroy(gev->src); g_source_unref(gev->src); } g_free(gev); } return NULL; }
Bool VmBackup_SendEvent(const char *event, const uint32 code, const char *desc) { Bool success; char *result = NULL; size_t resultLen; gchar *msg; ASSERT(gBackupState != NULL); g_debug("*** %s\n", __FUNCTION__); if (gBackupState->keepAlive != NULL) { g_source_destroy(gBackupState->keepAlive); g_source_unref(gBackupState->keepAlive); } msg = g_strdup_printf(VMBACKUP_PROTOCOL_EVENT_SET" %s %u %s", event, code, desc); g_debug("Sending vmbackup event: %s\n", msg); #if defined(__linux__) if (gBackupState->needsPriv) { success = VmBackupPrivSendMsg(msg, &result, &resultLen); } else { success = RpcChannel_Send(gBackupState->ctx->rpc, msg, strlen(msg) + 1, &result, &resultLen); if (!success) { const char *privErr = "Guest is not privileged"; if (resultLen > strlen(privErr) && strncmp(result, privErr, strlen(privErr)) == 0) { g_debug("Failed to send event: %s\n", result); vm_free(result); /* * PR1444259: * Some hosts enforce privilege elevation for sending this * event, especially 5.5. This is Linux specific because * version 9.4.x on Linux only triggers host side check for * privilege elevation by sending iopl_elevation capability * to the host. */ gBackupState->needsPriv = TRUE; g_debug("Sending event with priv: %s\n", msg); success = VmBackupPrivSendMsg(msg, &result, &resultLen); } else { gBackupState->needsPriv = FALSE; } } } #else success = RpcChannel_Send(gBackupState->ctx->rpc, msg, strlen(msg) + 1, &result, &resultLen); #endif if (!success) { g_warning("Failed to send vmbackup event: %s.\n", result); } vm_free(result); g_free(msg); gBackupState->keepAlive = g_timeout_source_new(VMBACKUP_KEEP_ALIVE_PERIOD / 2); VMTOOLSAPP_ATTACH_SOURCE(gBackupState->ctx, gBackupState->keepAlive, VmBackupKeepAliveCallback, NULL, NULL); return success; }
/** * CommandIfaceStartNB(): _non-blocking_ start request * * @param pMgr Pointer to the parent test command manager (e.g., * for stopping test execution) * @param pMgrRd Command Manager's RuntimeDispatcher instance; * the command handler may use it for running its * own logic, if needed. */ void CommandIfaceStartNB(TestCmdMgr* pMgr, wsf::RuntimeDispatcher* pMgrRd) { UTIL_PRINT_LINE("%s: Starting...", args_[0]); class StartRaii { public: StartRaii() : pThreadCtx(NULL) { } ~StartRaii() { if (pThreadCtx) { PmSockThreadCtxUnref(pThreadCtx); } } public: PmSockThreadContext* pThreadCtx; };//class StartRaii StartRaii raii; GMainLoop* const gmainloop = (GMainLoop*)wsf::RuntimeDispatcher::GetInternalLoop(*pMgrRd); assert(gmainloop); GMainContext* const gmainctx = ::g_main_loop_get_context(gmainloop); assert(gmainctx); /// Create a palmsocket thread context PslError pslErr = ::PmSockThreadCtxNewFromGMain( gmainctx, args_[0], &raii.pThreadCtx); if (pslErr) { const std::string errorMsg = std::string("PmSockThreadCtxNewFromGMain failed: ") + ::PmSockErrStringFromError(pslErr); UTIL_THROW_FATAL(args_[0], errorMsg.c_str()); } pslErr = ::PmSockCreateChannel( raii.pThreadCtx, (PmSockOptionFlags)0/*options*/, args_[0], &pChan_); if (!pslErr) { assert(pChan_); } else { const std::string errorMsg( std::string("PmSockCreateChannel failed: ") + ::PmSockErrStringFromError(pslErr)); UTIL_THROW_FATAL(args_[0], errorMsg.c_str()); } GSource* pTimeout = g_timeout_source_new(0/*interval*/); g_source_set_priority(pTimeout, G_PRIORITY_LOW); g_source_set_callback(pTimeout, &TimeoutGSourceFunc, this, NULL/*GDestroyNotify*/); g_source_attach(pTimeout, gmainctx); g_source_unref(pTimeout); }//CommandIfaceStartNB
void GTimeout::add(unsigned int milliseconds, Slot0<bool> *slot) { GSource *source = g_timeout_source_new(milliseconds); add_impl(source, gcallback, slot); }
/** * mate_bg_crossfade_start: * @fade: a #MateBGCrossfade * @window: The #GdkWindow to draw crossfade on * * This function initiates a quick crossfade between two surfaces on * the background of @window. Before initiating the crossfade both * mate_bg_crossfade_set_start_surface() and * mate_bg_crossfade_set_end_surface() need to be called. If animations * are disabled, the crossfade is skipped, and the window background is * set immediately to the end surface. **/ void mate_bg_crossfade_start (MateBGCrossfade *fade, GdkWindow *window) { GSource *source; GMainContext *context; g_return_if_fail (MATE_IS_BG_CROSSFADE (fade)); g_return_if_fail (window != NULL); g_return_if_fail (fade->priv->start_surface != NULL); g_return_if_fail (fade->priv->end_surface != NULL); g_return_if_fail (!mate_bg_crossfade_is_started (fade)); g_return_if_fail (gdk_window_get_window_type (window) != GDK_WINDOW_FOREIGN); /* If drawing is done on the root window, * it is essential to have the root pixmap. */ if (gdk_window_get_window_type (window) == GDK_WINDOW_ROOT) { GdkDisplay *display = gdk_window_get_display (window); cairo_surface_t *surface = get_root_pixmap_id_surface (display); g_return_if_fail (surface != NULL); cairo_surface_destroy (surface); } if (fade->priv->fading_surface != NULL) { cairo_surface_destroy (fade->priv->fading_surface); fade->priv->fading_surface = NULL; } fade->priv->window = window; if (gdk_window_get_window_type (fade->priv->window) != GDK_WINDOW_ROOT) { fade->priv->fading_surface = tile_surface (fade->priv->start_surface, fade->priv->width, fade->priv->height); if (fade->priv->widget != NULL) { g_signal_connect (fade->priv->widget, "draw", (GCallback) on_widget_draw, fade); } } else { cairo_t *cr; GdkDisplay *display = gdk_window_get_display (fade->priv->window); fade->priv->fading_surface = get_root_pixmap_id_surface (display); cr = cairo_create (fade->priv->fading_surface); cairo_set_source_surface (cr, fade->priv->start_surface, 0, 0); cairo_paint (cr); cairo_destroy (cr); } draw_background (fade); source = g_timeout_source_new (1000 / 60.0); g_source_set_callback (source, (GSourceFunc) on_tick, fade, (GDestroyNotify) on_finished); context = g_main_context_default (); fade->priv->timeout_id = g_source_attach (source, context); g_source_unref (source); fade->priv->is_first_frame = TRUE; fade->priv->total_duration = .75; fade->priv->start_time = get_current_time (); }