/** ======================================================================== * The 'dispatch' function of GSourceFuncs * * @param base * @param opaqueCb @see GSourceFuncs * @param userData @see GSourceFuncs * * @return gboolean @see GSourceFuncs * * ========================================================================= */ static gboolean multi_fd_watch_dispatch(GSource* const base, GSourceFunc opaqueCb, gpointer userData) { PslMultiFdWatchSource* const source = (PslMultiFdWatchSource*)base; PslMultiFdWatchSourceCb* const cb = (PslMultiFdWatchSourceCb*)opaqueCb; source->restartTimer = true; ///< so it will restart at next poll prepare if (!cb) { PSL_LOG_ERROR("%s (watch=%p): ERROR: multi-fd watch dispatch with " \ "NULL user callback ptr: did you forget to call " \ "g_source_set_callback()?", __func__, base); return false; } PSL_LOG_DEBUGLOW("%s (watch=%p): preparing to call user's callback", __func__, base); /// Construct an array of ready PollFD's if (source->cachedReadyPollFdArray->len > 0) { g_array_set_size(source->cachedReadyPollFdArray, 0); } gpointer key, value; GHashTableIter iter; g_hash_table_iter_init(&iter, source->descTable); while (g_hash_table_iter_next(&iter, &key, &value)) { const GPollFD* const pollFd = &((PslMultiFdDescriptor*)value)->pollFd; PSL_LOG_DEBUGLOW( "%s (watch=%p): iter: table=%p, desc=%p, fd=%d, " \ "GIOCondition=(mon:0x%lX, ind:0x%lX)", __func__, source, source->descTable, value, (int)pollFd->fd, (unsigned long)pollFd->events, (unsigned long)pollFd->revents); if ((pollFd->revents & MULTI_FD_WATCH_PERM_FAILURE_IO_CONDS) != 0) { PSL_LOG_ERROR("%s: (watch=%p): I/O FAILURE on fd=%d: indicated " \ "GIOCondition=0x%lX", __func__, source, (int)pollFd->fd, (unsigned long)pollFd->revents); } const GIOCondition currentCondition = pollFd->revents & (pollFd->events | MULTI_FD_WATCH_PERM_FAILURE_IO_CONDS); if (currentCondition) { const PslMultiFdPollRec pollRec = { .fd = pollFd->fd, .reqEvents = pollFd->events, .indEvents = currentCondition }; g_array_append_vals(source->cachedReadyPollFdArray, &pollRec, 1); } } /// Dispatch the callback const gint numrecs = source->cachedReadyPollFdArray->len; const PslMultiFdPollRec* const pollrecs = ((numrecs > 0) ? (PslMultiFdPollRec*)source->cachedReadyPollFdArray->data : NULL); PSL_LOG_DEBUGLOW("%s (watch=%p): Calling user's callback: " \ "pollrec array=%p, numelts=%d", __func__, base, pollrecs, (int)numrecs); const gboolean stayAttached = cb(userData, pollrecs, numrecs); if (!stayAttached) { PSL_LOG_DEBUG("%s (watch=%p): user cb requested removal of source", __func__, base); } return stayAttached; } //multi_fd_watch_dispatch /** ======================================================================== * The 'finalize' function of GSourceFuncs * * @param base * * ========================================================================= */ static void multi_fd_watch_finalize(GSource* base) { PSL_LOG_DEBUG("%s (watch=%p)", __func__, base); PslMultiFdWatchSource* const source = (PslMultiFdWatchSource*)base; /** * @note We may be called with our own data members in a * partially-constructed (but initialized) state if * psl_multi_fd_watch_new failed part way through and * called g_source_unref. */ if (source->descTable) { /** * @note our "superclass" GSource takes care of removing * our pollFds record pointers from the source's and the * gmain context's pollFd lists when the GSource instance * is being detached from the gmain context, so we don't * need to do it ourselves. */ g_hash_table_destroy(source->descTable); } if (source->cachedReadyPollFdArray) { (void)g_array_free(source->cachedReadyPollFdArray, true/*free_segment*/); } }
static void build_append_array(GArray *array, GArray *val) { g_array_append_vals(array, val->data, val->len); }
gboolean uat_save(uat_t* uat, const char** error) { guint i; gchar* fname = uat_get_actual_filename(uat,TRUE); FILE* fp; if (! fname ) return FALSE; fp = ws_fopen(fname,"w"); if (!fp && errno == ENOENT) { /* Parent directory does not exist, try creating first */ gchar *pf_dir_path = NULL; if (create_persconffile_dir(&pf_dir_path) != 0) { *error = ep_strdup_printf("uat_save: error creating '%s'", pf_dir_path); g_free (pf_dir_path); return FALSE; } fp = ws_fopen(fname,"w"); } if (!fp) { *error = ep_strdup_printf("uat_save: error opening '%s': %s",fname,g_strerror(errno)); return FALSE; } *error = NULL; g_free (fname); /* Ensure raw_data is synced with user_data and all "good" entries have been accounted for */ /* Start by clearing current user_data */ for ( i = 0 ; i < uat->user_data->len ; i++ ) { if (uat->free_cb) { uat->free_cb(UAT_USER_INDEX_PTR(uat,i)); } } g_array_set_size(uat->user_data,0); *((uat)->user_ptr) = NULL; *((uat)->nrows_p) = 0; /* Now copy "good" raw_data entries to user_data */ for ( i = 0 ; i < uat->raw_data->len ; i++ ) { void* rec = uat->raw_data->data + (uat->record_size * i); gboolean* valid = (gboolean*)(uat->valid_data->data + sizeof(gboolean)*i); if (*valid) { g_array_append_vals(uat->user_data, rec, 1); if (uat->copy_cb) { uat->copy_cb(UAT_USER_INDEX_PTR(uat,i), rec, (unsigned int) uat->record_size); } UAT_UPDATE(uat); } } fprintf(fp,"# This file is automatically generated, DO NOT MODIFY.\n"); for ( i = 0 ; i < uat->user_data->len ; i++ ) { void* rec = uat->user_data->data + (uat->record_size * i); uat_field_t* f; guint j; f = uat->fields; for( j=0 ; j < uat->ncols ; j++ ) { putfld(fp, rec, &(f[j])); fputs((j == uat->ncols - 1) ? "\n" : "," ,fp); } } fclose(fp); uat->changed = FALSE; return TRUE; }
// chain function - this function does the actual processing static GstFlowReturn gst_bgfg_acmmm2003_chain(GstPad *pad, GstBuffer *buf) { GstBgFgACMMM2003 *filter; // sanity checks g_return_val_if_fail(pad != NULL, GST_FLOW_ERROR); g_return_val_if_fail(buf != NULL, GST_FLOW_ERROR); filter = GST_BGFG_ACMMM2003(GST_OBJECT_PARENT(pad)); filter->image->imageData = (gchar*) GST_BUFFER_DATA(buf); // the bg model must be initialized with a valid image; thus we delay its // creation until the chain function if (filter->model == NULL) { filter->model = cvCreateFGDStatModel(filter->image, NULL); ((CvFGDStatModel*)filter->model)->params.minArea = filter->min_area; ((CvFGDStatModel*)filter->model)->params.erode_iterations = filter->n_erode_iterations; ((CvFGDStatModel*)filter->model)->params.dilate_iterations = filter->n_dilate_iterations; return gst_pad_push(filter->srcpad, buf); } cvUpdateBGStatModel(filter->image, filter->model, -1); // send mask event, if requested if (filter->send_mask_events) { GstStructure *structure; GstEvent *event; GArray *data_array; IplImage *mask; // prepare and send custom event with the mask surface mask = filter->model->foreground; data_array = g_array_sized_new(FALSE, FALSE, sizeof(mask->imageData[0]), mask->imageSize); g_array_append_vals(data_array, mask->imageData, mask->imageSize); structure = gst_structure_new("bgfg-mask", "data", G_TYPE_POINTER, data_array, "width", G_TYPE_UINT, mask->width, "height", G_TYPE_UINT, mask->height, "depth", G_TYPE_UINT, mask->depth, "channels", G_TYPE_UINT, mask->nChannels, "timestamp", G_TYPE_UINT64, GST_BUFFER_TIMESTAMP(buf), NULL); event = gst_event_new_custom(GST_EVENT_CUSTOM_DOWNSTREAM, structure); gst_pad_push_event(filter->srcpad, event); g_array_unref(data_array); if (filter->display) { // shade the regions not selected by the acmmm2003 algorithm cvXorS(mask, CV_RGB(255, 255, 255), mask, NULL); cvSubS(filter->image, CV_RGB(191, 191, 191), filter->image, mask); cvXorS(mask, CV_RGB(255, 255, 255), mask, NULL); } } if (filter->send_roi_events) { CvSeq *contour; CvRect *bounding_rects; guint i, j, n_rects; // count # of contours, allocate array to store the bounding rectangles for (contour = filter->model->foreground_regions, n_rects = 0; contour != NULL; contour = contour->h_next, ++n_rects); bounding_rects = g_new(CvRect, n_rects); for (contour = filter->model->foreground_regions, i = 0; contour != NULL; contour = contour->h_next, ++i) bounding_rects[i] = cvBoundingRect(contour, 0); for (i = 0; i < n_rects; ++i) { // skip collapsed rectangles if ((bounding_rects[i].width == 0) || (bounding_rects[i].height == 0)) continue; for (j = (i + 1); j < n_rects; ++j) { // skip collapsed rectangles if ((bounding_rects[j].width == 0) || (bounding_rects[j].height == 0)) continue; if (rect_overlap(bounding_rects[i], bounding_rects[j])) { bounding_rects[i] = rect_collapse(bounding_rects[i], bounding_rects[j]); bounding_rects[j] = NULL_RECT; } } } for (i = 0; i < n_rects; ++i) { GstEvent *event; GstStructure *structure; CvRect r; // skip collapsed rectangles r = bounding_rects[i]; if ((r.width == 0) || (r.height == 0)) continue; structure = gst_structure_new("bgfg-roi", "x", G_TYPE_UINT, r.x, "y", G_TYPE_UINT, r.y, "width", G_TYPE_UINT, r.width, "height", G_TYPE_UINT, r.height, "timestamp", G_TYPE_UINT64, GST_BUFFER_TIMESTAMP(buf), NULL); event = gst_event_new_custom(GST_EVENT_CUSTOM_DOWNSTREAM, structure); gst_pad_send_event(filter->sinkpad, event); if (filter->verbose) GST_INFO("[roi] x: %d, y: %d, width: %d, height: %d\n", r.x, r.y, r.width, r.height); if (filter->display) cvRectangle(filter->image, cvPoint(r.x, r.y), cvPoint(r.x + r.width, r.y + r.height), CV_RGB(0, 0, 255), 1, 0, 0); } g_free(bounding_rects); } if (filter->display) gst_buffer_set_data(buf, (guchar*) filter->image->imageData, filter->image->imageSize); return gst_pad_push(filter->srcpad, buf); }
/*! \brief Draw a page. * \par Function Description * Draws the \a page on the Cairo context \a cr, which should have * dimensions \a cr_width and \a cr_height. If the Pango context \a * pc is provided, it is used for rendering of text. The parameter \a * is_color controls whether to enable color printing, and \a * is_raster should be set if drawing to a raster surface such as an * image. * * \param toplevel A #TOPLEVEL structure. * \param page The #PAGE to be rendered. * \param cr The Cairo context to render to. * \param pc A Pango context for text rendering, or NULL. * \param cr_width The width of the drawing area. * \param cr_height The height of the drawing area. * \param is_color TRUE if drawing should be in color; FALSE otherwise. * \param is_raster TRUE if drawing to a raster image surface; FALSE otherwise. */ static void x_print_draw_page (TOPLEVEL *toplevel, PAGE *page, cairo_t *cr, PangoContext *pc, double cr_width, double cr_height, gboolean is_color, gboolean is_raster) { EdaRenderer *renderer; cairo_matrix_t mtx; GArray *color_map; int status, wx_min, wy_min, wx_max, wy_max; double w_width, w_height, scale; GList *iter; /* First, calculate a transformation matrix for the cairo * context. We want to center the extents of the page in the * available page area. */ status = world_get_object_glist_bounds (toplevel, s_page_objects (page), &wx_min, &wy_min, &wx_max, &wy_max); /* If there are no printable objects, draw nothing. */ if (!status) return; w_width = wx_max - wx_min; w_height = wy_max - wy_min; scale = fmin (cr_width / w_width, cr_height / w_height); cairo_matrix_init (&mtx, scale, 0, 0, -scale, - (wx_min + 0.5*w_width) * scale + 0.5*cr_width, (wy_min + 0.5*w_height) * scale + 0.5*cr_height); /* Second, build the color map. If no color printing is desired, * transform the print color map into a black-and-white color map by * making the background color transparent and replacing all other * enabled colors with solid black. */ color_map = g_array_sized_new (FALSE, FALSE, sizeof(GedaColor), MAX_COLORS); color_map = g_array_append_vals (color_map, print_colors, MAX_COLORS); if (!is_color) { int i; for (i = 0; i < MAX_COLORS; i++) { GedaColor *c = &g_array_index (color_map, GedaColor, i); if (!c->enabled) continue; /* Disable background color & fully-transparent colors */ if (c->a == 0 || i == BACKGROUND_COLOR) { c->enabled = FALSE; continue; } /* Set any remaining colors solid black */ c->r = 0; c->g = 0; c->b = 0; c->a = ~0; } } /* Thirdly, create and initialise a renderer */ renderer = g_object_new (EDA_TYPE_RENDERER, "cairo-context", cr, "pango-context", pc, "color-map", color_map, "render-flags", is_raster ? EDA_RENDERER_FLAG_HINTING : 0, NULL); /* Finally, actually do drawing */ cairo_save (cr); cairo_transform (cr, &mtx); /* Draw background */ eda_cairo_set_source_color (cr, BACKGROUND_COLOR, color_map); cairo_paint (cr); /* Draw all objects and cues */ for (iter = (GList *) s_page_objects (page); iter != NULL; iter = g_list_next (iter)) { eda_renderer_draw (renderer, (OBJECT *) iter->data); } for (iter = (GList *) s_page_objects (page); iter != NULL; iter = g_list_next (iter)) { eda_renderer_draw_cues (renderer, (OBJECT *) iter->data); } cairo_restore (cr); g_object_unref (renderer); g_array_free (color_map, TRUE); }
static GError* _cache_load_from_m0(struct meta1_prefixes_set_s *m1ps, const gchar *ns_name, const struct addr_info_s *local_addr, struct addr_info_s *m0_addr, GArray **updated_prefixes, gboolean *meta0_ok) { GError *err = NULL; GSList *m0info_list = NULL; EXTRA_ASSERT(m1ps != NULL); GRID_TRACE2("%s(%p,%s,%p,%p)", __FUNCTION__, m1ps, ns_name, local_addr, m0_addr); (void)ns_name; gchar m0[STRLEN_ADDRINFO]; grid_addrinfo_to_string (m0_addr, m0, sizeof(m0)); err = meta0_remote_get_meta1_all(m0, &m0info_list); if (err) { g_prefix_error(&err, "Remote error: "); return err; } if (!m0info_list) { GRID_DEBUG("META0 has no prefix configured!"); return NULL; } *meta0_ok = TRUE; guint8 *cache = _cache_from_m0l(m0info_list, local_addr); GPtrArray *by_prefix = meta0_utils_list_to_array(m0info_list); g_mutex_lock(&m1ps->lock); GRID_DEBUG("Got %u prefixes from M0, %u in place", by_prefix->len, m1ps->by_prefix ? m1ps->by_prefix->len : 0); if ( m1ps->by_prefix ) { guint prefix; *updated_prefixes = g_array_new(FALSE, FALSE, sizeof(guint16)); for( prefix=0 ; prefix <65536 ;prefix++) { if ( _cache_is_managed(m1ps->cache,(guint8 *)&prefix) != _cache_is_managed( cache,(guint8 *)&prefix)) { g_array_append_vals(*updated_prefixes, &prefix, 1); } } } SWAP_PTR(m1ps->by_prefix, by_prefix); SWAP_PTR(m1ps->cache, cache); g_mutex_unlock(&m1ps->lock); if (by_prefix) meta0_utils_array_clean(by_prefix); by_prefix = NULL; if (cache) g_free(cache); cache = NULL; g_slist_foreach(m0info_list, meta0_info_gclean, NULL); g_slist_free(m0info_list); return NULL; }
// Store (key,value) pairs from a GHashTable in the kwallet. // Every 'slot' has to take care of it's own data. gboolean dt_pwstorage_kwallet_set(const backend_kwallet_context_t *context, const gchar* slot, GHashTable* table) { printf("slot %s\n", slot); GArray* byte_array = g_array_new(FALSE, FALSE, sizeof(gchar)); GHashTableIter iter; g_hash_table_iter_init (&iter, table); gpointer key, value; guint size = g_hash_table_size(table); size = GINT_TO_BE(size); g_array_append_vals(byte_array, &size, sizeof(guint)/sizeof(gchar)); while (g_hash_table_iter_next (&iter, &key, &value)) { dt_print(DT_DEBUG_PWSTORAGE,"[pwstorage_kwallet_set] storing (%s, %s)\n",(gchar*)key, (gchar*)value); gsize length; gchar* new_key = char2qstring(key, &length); if(new_key == NULL) { g_free(g_array_free(byte_array, FALSE)); return FALSE; } g_array_append_vals(byte_array, new_key, length); g_free(new_key); gchar* new_value = char2qstring(value, &length); if(new_value == NULL) { g_free(g_array_free(byte_array, FALSE)); return FALSE; } g_array_append_vals(byte_array, new_value, length); g_free(new_value); } int wallet_handle = get_wallet_handle(context); GError* error = NULL; /* signature: * * in i handle, * in s folder, * in s key, * in ay value, * in s appid, * * out i arg_0 */ GVariant *ret = g_dbus_proxy_call_sync(context->proxy, "writeMap", g_variant_new("(iss@ays)", wallet_handle, kwallet_folder, slot, g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING, byte_array->data, byte_array->len, TRUE, g_free, byte_array->data), app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); g_array_free(byte_array, FALSE); if(check_error(error)) { g_variant_unref(ret); return FALSE; } GVariant *child = g_variant_get_child_value(ret, 0); int return_code = g_variant_get_int32(child); g_variant_unref(child); g_variant_unref(ret); if (return_code != 0) dt_print(DT_DEBUG_PWSTORAGE,"[pwstorage_kwallet_set] Warning: bad return code %d from kwallet\n", return_code); return return_code == 0; }
static Aml *aml_gpio_connection(AmlGpioConnectionType type, AmlConsumerAndProducer con_and_pro, uint8_t flags, AmlPinConfig pin_config, uint16_t output_drive, uint16_t debounce_timeout, const uint32_t pin_list[], uint32_t pin_count, const char *resource_source_name, const uint8_t *vendor_data, uint16_t vendor_data_len) { Aml *var = aml_alloc(); const uint16_t min_desc_len = 0x16; uint16_t resource_source_name_len, length; uint16_t pin_table_offset, resource_source_name_offset, vendor_data_offset; uint32_t i; assert(resource_source_name); resource_source_name_len = strlen(resource_source_name) + 1; length = min_desc_len + resource_source_name_len + vendor_data_len; pin_table_offset = min_desc_len + 1; resource_source_name_offset = pin_table_offset + pin_count * 2; vendor_data_offset = resource_source_name_offset + resource_source_name_len; build_append_byte(var->buf, 0x8C); /* GPIO Connection Descriptor */ build_append_int_noprefix(var->buf, length, 2); /* Length */ build_append_byte(var->buf, 1); /* Revision ID */ build_append_byte(var->buf, type); /* GPIO Connection Type */ /* General Flags (2 bytes) */ build_append_int_noprefix(var->buf, con_and_pro, 2); /* Interrupt and IO Flags (2 bytes) */ build_append_int_noprefix(var->buf, flags, 2); /* Pin Configuration 0 = Default 1 = Pull-up 2 = Pull-down 3 = No Pull */ build_append_byte(var->buf, pin_config); /* Output Drive Strength (2 bytes) */ build_append_int_noprefix(var->buf, output_drive, 2); /* Debounce Timeout (2 bytes) */ build_append_int_noprefix(var->buf, debounce_timeout, 2); /* Pin Table Offset (2 bytes) */ build_append_int_noprefix(var->buf, pin_table_offset, 2); build_append_byte(var->buf, 0); /* Resource Source Index */ /* Resource Source Name Offset (2 bytes) */ build_append_int_noprefix(var->buf, resource_source_name_offset, 2); /* Vendor Data Offset (2 bytes) */ build_append_int_noprefix(var->buf, vendor_data_offset, 2); /* Vendor Data Length (2 bytes) */ build_append_int_noprefix(var->buf, vendor_data_len, 2); /* Pin Number (2n bytes)*/ for (i = 0; i < pin_count; i++) { build_append_int_noprefix(var->buf, pin_list[i], 2); } /* Resource Source Name */ build_append_namestring(var->buf, "%s", resource_source_name); build_append_byte(var->buf, '\0'); /* Vendor-defined Data */ if (vendor_data != NULL) { g_array_append_vals(var->buf, vendor_data, vendor_data_len); } return var; }
static gboolean panel_multiscreen_get_randr_monitors_for_screen (GdkScreen *screen, int *monitors_ret, GdkRectangle **geometries_ret) { #ifdef HAVE_RANDR Display *xdisplay; Window xroot; XRRScreenResources *resources; RROutput primary; GArray *geometries; int i; if (!have_randr) return FALSE; /* GTK+ 2.14.x uses the Xinerama API, instead of RANDR, to get the * monitor geometries. It does this to avoid calling * XRRGetScreenResources(), which is slow as it re-detects all the * monitors --- note that XRRGetScreenResourcesCurrent() had not been * introduced yet. Using Xinerama in GTK+ has the bad side effect that * gdk_screen_get_monitor_plug_name() will return NULL, as Xinerama * does not provide that information, unlike RANDR. * * Here we need to identify the output names, so that we can put the * built-in LCD in a laptop *before* all other outputs. This is so * that mate-panel will normally prefer to appear on the "native" * display rather than on an external monitor. * * To get the output names and geometries, we will not use * gdk_screen_get_n_monitors() and friends, but rather we will call * XRR*() directly. * * See https://bugzilla.novell.com/show_bug.cgi?id=479684 for this * particular bug, and and * http://bugzilla.gnome.org/show_bug.cgi?id=562944 for a more * long-term solution. */ xdisplay = GDK_SCREEN_XDISPLAY (screen); xroot = GDK_WINDOW_XID (gdk_screen_get_root_window (screen)); resources = XRRGetScreenResourcesCurrent (xdisplay, xroot); if (resources->noutput == 0) { /* This might happen if nothing tried to get randr * resources from the server before, so we need an * active probe. See comment #27 in * https://bugzilla.gnome.org/show_bug.cgi?id=597101 */ XRRFreeScreenResources (resources); resources = XRRGetScreenResources (xdisplay, xroot); } if (!resources) return FALSE; primary = XRRGetOutputPrimary (xdisplay, xroot); geometries = g_array_sized_new (FALSE, FALSE, sizeof (GdkRectangle), resources->noutput); for (i = 0; i < resources->noutput; i++) { XRROutputInfo *output; output = XRRGetOutputInfo (xdisplay, resources, resources->outputs[i]); if (output->connection != RR_Disconnected && output->crtc != 0) { XRRCrtcInfo *crtc; GdkRectangle rect; crtc = XRRGetCrtcInfo (xdisplay, resources, output->crtc); rect.x = crtc->x; rect.y = crtc->y; rect.width = crtc->width; rect.height = crtc->height; XRRFreeCrtcInfo (crtc); if (_panel_multiscreen_output_should_be_first (xdisplay, resources->outputs[i], output, primary)) g_array_prepend_vals (geometries, &rect, 1); else g_array_append_vals (geometries, &rect, 1); } XRRFreeOutputInfo (output); } XRRFreeScreenResources (resources); if (geometries->len == 0) { /* This can happen in at least one case: * https://bugzilla.novell.com/show_bug.cgi?id=543876 where all * monitors appear disconnected (possibly because the screen * is behing a KVM switch) -- see comment #8. * There might be other cases too, so we stay on the safe side. */ g_array_free (geometries, TRUE); return FALSE; } *monitors_ret = geometries->len; *geometries_ret = (GdkRectangle *) g_array_free (geometries, FALSE); return TRUE; #else return FALSE; #endif }
/** * Attempts to query sample data from the oscilloscope in order to send it * to the session bus for further processing. * * @param fd The file descriptor used as the event source. * @param revents The received events. * @param cb_data Callback data, in this case our device instance. * * @return TRUE in case of success or a recoverable error, * FALSE when a fatal error was encountered. */ SR_PRIV int dlm_data_receive(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct scope_state *model_state; struct dev_context *devc; struct sr_channel *ch; struct sr_datafeed_packet packet; int chunk_len, num_bytes; static GArray *data = NULL; (void)fd; (void)revents; if (!(sdi = cb_data)) return FALSE; if (!(devc = sdi->priv)) return FALSE; if (!(model_state = (struct scope_state*)devc->model_state)) return FALSE; /* Are we waiting for a response from the device? */ if (!devc->data_pending) return TRUE; /* Check if a new query response is coming our way. */ if (!data) { if (sr_scpi_read_begin(sdi->conn) == SR_OK) /* The 16 here accounts for the header and EOL. */ data = g_array_sized_new(FALSE, FALSE, sizeof(uint8_t), 16 + model_state->samples_per_frame); else return TRUE; } /* Store incoming data. */ chunk_len = sr_scpi_read_data(sdi->conn, devc->receive_buffer, RECEIVE_BUFFER_SIZE); if (chunk_len < 0) { sr_err("Error while reading data: %d", chunk_len); goto fail; } g_array_append_vals(data, devc->receive_buffer, chunk_len); /* Read the entire query response before processing. */ if (!sr_scpi_read_complete(sdi->conn)) return TRUE; /* We finished reading and are no longer waiting for data. */ devc->data_pending = FALSE; /* Signal the beginning of a new frame if this is the first channel. */ if (devc->current_channel == devc->enabled_channels) { packet.type = SR_DF_FRAME_BEGIN; sr_session_send(sdi, &packet); } if (dlm_block_data_header_process(data, &num_bytes) != SR_OK) { sr_err("Encountered malformed block data header."); goto fail; } if (num_bytes == 0) { sr_warn("Zero-length waveform data packet received. " \ "Live mode not supported yet, stopping " \ "acquisition and retrying."); /* Don't care about return value here. */ dlm_acquisition_stop(sdi->conn); g_array_free(data, TRUE); dlm_channel_data_request(sdi); return TRUE; } ch = devc->current_channel->data; switch (ch->type) { case SR_CHANNEL_ANALOG: if (dlm_analog_samples_send(data, &model_state->analog_states[ch->index], sdi) != SR_OK) goto fail; break; case SR_CHANNEL_LOGIC: if (dlm_digital_samples_send(data, sdi) != SR_OK) goto fail; break; default: sr_err("Invalid channel type encountered."); break; } g_array_free(data, TRUE); data = NULL; /* * Signal the end of this frame if this was the last enabled channel * and set the next enabled channel. Then, request its data. */ if (!devc->current_channel->next) { packet.type = SR_DF_FRAME_END; sr_session_send(sdi, &packet); devc->current_channel = devc->enabled_channels; /* * As of now we only support importing the current acquisition * data so we're going to stop at this point. */ sdi->driver->dev_acquisition_stop(sdi, cb_data); return TRUE; } else devc->current_channel = devc->current_channel->next; if (dlm_channel_data_request(sdi) != SR_OK) { sr_err("Failed to request acquisition data."); goto fail; } return TRUE; fail: if (data) { g_array_free(data, TRUE); data = NULL; } return FALSE; }
CK_RV gkm_aes_mechanism_unwrap (GkmSession *session, CK_MECHANISM_PTR mech, GkmObject *wrapper, CK_VOID_PTR input, CK_ULONG n_input, CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs, GkmObject **unwrapped) { gcry_cipher_hd_t cih; gcry_error_t gcry; CK_ATTRIBUTE attr; GArray *array; GkmAesKey *key; gpointer padded, value; gsize n_padded, n_value; GkmTransaction *transaction; gsize block, pos; gboolean ret; g_return_val_if_fail (GKM_IS_SESSION (session), CKR_GENERAL_ERROR); g_return_val_if_fail (mech, CKR_GENERAL_ERROR); g_return_val_if_fail (mech->mechanism == CKM_AES_CBC_PAD, CKR_GENERAL_ERROR); g_return_val_if_fail (GKM_IS_OBJECT (wrapper), CKR_GENERAL_ERROR); if (!GKM_IS_AES_KEY (wrapper)) return CKR_WRAPPING_KEY_TYPE_INCONSISTENT; key = GKM_AES_KEY (wrapper); block = gkm_aes_key_get_block_size (key); g_return_val_if_fail (block != 0, CKR_GENERAL_ERROR); if (n_input == 0 || n_input % block != 0) return CKR_WRAPPED_KEY_LEN_RANGE; cih = gkm_aes_key_get_cipher (key, GCRY_CIPHER_MODE_CBC); if (cih == NULL) return CKR_FUNCTION_FAILED; if (!mech->pParameter || gcry_cipher_setiv (cih, mech->pParameter, mech->ulParameterLen) != 0) { gcry_cipher_close (cih); return CKR_MECHANISM_PARAM_INVALID; } padded = egg_secure_alloc (n_input); memcpy (padded, input, n_input); n_padded = n_input; /* In place decryption */ for (pos = 0; pos < n_padded; pos += block) { gcry = gcry_cipher_decrypt (cih, (guchar*)padded + pos, block, NULL, 0); g_return_val_if_fail (gcry == 0, CKR_GENERAL_ERROR); } gcry_cipher_close (cih); /* Unpad the resulting value */ ret = egg_padding_pkcs7_unpad (egg_secure_realloc, block, padded, n_padded, &value, &n_value); egg_secure_free (padded); /* TODO: This is dubious, there doesn't seem to be an rv for 'bad decrypt' */ if (ret == FALSE) return CKR_WRAPPED_KEY_INVALID; /* Now setup the attributes with our new value */ array = g_array_new (FALSE, FALSE, sizeof (CK_ATTRIBUTE)); /* Prepend the value */ attr.type = CKA_VALUE; attr.pValue = value; attr.ulValueLen = n_value; g_array_append_val (array, attr); /* Add the remainder of the attributes */ g_array_append_vals (array, attrs, n_attrs); transaction = gkm_transaction_new (); /* Now create an object with these attributes */ *unwrapped = gkm_session_create_object_for_attributes (session, transaction, (CK_ATTRIBUTE_PTR)array->data, array->len); egg_secure_free (value); g_array_free (array, TRUE); return gkm_transaction_complete_and_unref (transaction); }
// push in one Scope Id int s_stack_push (SymbolTableStack* stack, ScopeId sid) { stack->stack = g_array_append_vals ( stack->stack, (gconstpointer) (&sid), 1 ); stack->top ++; return 0; }
static void collect_sessions (void) { g_autoptr(GHashTable) names_seen_before = NULL; GArray *xorg_search_array = NULL; GArray *wayland_search_array = NULL; gchar *session_dir = NULL; int i; const char *xorg_search_dirs[] = { "/etc/X11/sessions/", DMCONFDIR "/Sessions/", DATADIR "/gdm/BuiltInSessions/", DATADIR "/xsessions/", }; names_seen_before = g_hash_table_new (g_str_hash, g_str_equal); xorg_search_array = g_array_new (TRUE, TRUE, sizeof (char *)); const gchar * const *system_data_dirs = g_get_system_data_dirs (); for (i = 0; system_data_dirs[i]; i++) { session_dir = g_build_filename (system_data_dirs[i], "xsessions", NULL); g_array_append_val (xorg_search_array, session_dir); } g_array_append_vals (xorg_search_array, xorg_search_dirs, G_N_ELEMENTS (xorg_search_dirs)); #ifdef ENABLE_WAYLAND_SUPPORT const char *wayland_search_dirs[] = { DATADIR "/wayland-sessions/", }; wayland_search_array = g_array_new (TRUE, TRUE, sizeof (char *)); for (i = 0; system_data_dirs[i]; i++) { session_dir = g_build_filename (system_data_dirs[i], "wayland-sessions", NULL); g_array_append_val (wayland_search_array, session_dir); } g_array_append_vals (wayland_search_array, wayland_search_dirs, G_N_ELEMENTS (wayland_search_dirs)); #endif if (gdm_available_sessions_map == NULL) { gdm_available_sessions_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)gdm_session_file_free); } for (i = 0; i < xorg_search_array->len; i++) { collect_sessions_from_directory (g_array_index (xorg_search_array, gchar*, i)); } g_array_free (xorg_search_array, TRUE); #ifdef ENABLE_WAYLAND_SUPPORT #ifdef ENABLE_USER_DISPLAY_SERVER if (g_getenv ("WAYLAND_DISPLAY") == NULL && g_getenv ("RUNNING_UNDER_GDM") != NULL) { g_array_free (wayland_search_array, TRUE); return; } #endif for (i = 0; i < wayland_search_array->len; i++) { collect_sessions_from_directory (g_array_index (wayland_search_array, gchar*, i)); } g_array_free (wayland_search_array, TRUE); #endif g_hash_table_foreach_remove (gdm_available_sessions_map, remove_duplicate_sessions, names_seen_before); }
UString* ustring_append(UString* str, const UString* s) { return g_array_append_vals(str, s->data, s->len); }