/** * Rebuild all the tarifs from the data on the db. * * This should be used after you have initialized CCL. */ void CCL_tarif_rebuild_all(void) { GSList ** tarif = NULL; gint tarif_id; gint i; for (i = 0; -1 != (tarif_id = CCL_tarif_get_nth(i)); i++) _tarif_clear(tarif_id); g_datalist_clear(&ccl->tarifs); g_datalist_init(&ccl->tarifs); for (i = 0; -1 != (tarif_id = CCL_tarif_get_nth(i)); i++) { tarif = g_new0(GSList *, 1); *tarif = NULL; _tarif_rebuild(tarif_id, tarif); g_datalist_id_set_data(&ccl->tarifs, tarif_id, *tarif); g_free(tarif); } #ifdef DEBUG printf("CCL_tarif_rebuild_all(): [ %d ] Tariffs found\n", i); #endif }
static void _tarif_clear(gint tarif_id) { GSList **tarif = NULL; GSList *link = NULL; CCL_tarifpart *tp = NULL; GData *freed = NULL; tarif = g_new0(GSList *, 1); *tarif = g_datalist_id_get_data(&ccl->tarifs, tarif_id); g_assert(NULL != tarif); g_datalist_init(&freed); while ((link = g_slist_last(*tarif)) && *tarif) { *tarif = g_slist_remove_link(*tarif, link); tp = (CCL_tarifpart *) link->data; if (!g_datalist_id_get_data(&freed, GPOINTER_TO_INT(tp->prices))) { g_datalist_clear(tp->prices); g_datalist_id_set_data(&freed, GPOINTER_TO_INT(tp->prices), (void *)tp->prices); g_free(tp->prices); } g_slist_free_1(link); g_free(tp); } g_datalist_clear(&freed); *tarif = NULL; g_datalist_id_remove_data(&ccl->tarifs, tarif_id); g_free(tarif); }
static gboolean gst_object_set_name_default (GstObject * object) { const gchar *type_name; gint count; gchar *name; GQuark q; guint i, l; /* to ensure guaranteed uniqueness across threads, only one thread * may ever assign a name */ G_LOCK (object_name_mutex); if (!object_name_counts) { g_datalist_init (&object_name_counts); } q = g_type_qname (G_OBJECT_TYPE (object)); count = GPOINTER_TO_INT (g_datalist_id_get_data (&object_name_counts, q)); g_datalist_id_set_data (&object_name_counts, q, GINT_TO_POINTER (count + 1)); G_UNLOCK (object_name_mutex); /* GstFooSink -> foosink<N> */ type_name = g_quark_to_string (q); if (strncmp (type_name, "Gst", 3) == 0) type_name += 3; /* give the 20th "queue" element and the first "queue2" different names */ l = strlen (type_name); if (l > 0 && g_ascii_isdigit (type_name[l - 1])) { name = g_strdup_printf ("%s-%d", type_name, count); } else { name = g_strdup_printf ("%s%d", type_name, count); } l = strlen (name); for (i = 0; i < l; i++) name[i] = g_ascii_tolower (name[i]); GST_OBJECT_LOCK (object); if (G_UNLIKELY (object->parent != NULL)) goto had_parent; g_free (object->name); object->name = name; GST_OBJECT_UNLOCK (object); return TRUE; had_parent: { g_free (name); GST_WARNING ("parented objects can't be renamed"); GST_OBJECT_UNLOCK (object); return FALSE; } }
static void ServerPool_AddInstance (GQuark uid, GSocketService *service, GSocketConnection *incomingConnection) { Connection *handle = g_slice_new0 (Connection); handle->service = service; handle->incomingConnection = incomingConnection; g_datalist_id_set_data(&connectionPool, uid, handle); }
void nube_source_register(const gchar *name, void (*init_func)(NubeSource *source, gpointer user_data), void (*update_func)(NubeSource *source, gpointer user_data), gpointer user_data) { NubeSource *source = g_slice_new0(NubeSource); source->init_func = init_func; source->update_func = update_func; source->user_data = user_data; source->intervals_delay = 1; source->intervals_left = 1; g_datalist_id_set_data(&available_sources, g_quark_from_static_string(name), source); }
void _init_source(gpointer key, GQuark source_id, gpointer user_data) { NubeSource *source = g_datalist_id_get_data(&available_sources, source_id); if (!source) { g_printerr("Unknown source: %s\n", g_quark_to_string(source_id)); exit(1); } g_datalist_init(&source->data); source->init_func(source, source->user_data); g_datalist_id_set_data(&used_sources, source_id, source); }
static inline void g_object_notify_queue_thaw (GObject *object, GObjectNotifyQueue *nqueue) { GObjectNotifyContext *context = nqueue->context; GParamSpec *pspecs_mem[16], **pspecs, **free_me = NULL; GSList *slist; guint n_pspecs = 0; g_return_if_fail (nqueue->freeze_count > 0); nqueue->freeze_count--; if (nqueue->freeze_count) return; g_return_if_fail (object->ref_count > 0); pspecs = nqueue->n_pspecs > 16 ? free_me = g_new (GParamSpec*, nqueue->n_pspecs) : pspecs_mem; /* set first entry to NULL since it's checked unconditionally */ pspecs[0] = NULL; for (slist = nqueue->pspecs; slist; slist = slist->next) { GParamSpec *pspec = slist->data; gint i = 0; /* dedup, make pspecs in the list unique */ redo_dedup_check: if (pspecs[i] == pspec) continue; if (++i < n_pspecs) goto redo_dedup_check; pspecs[n_pspecs++] = pspec; } g_datalist_id_set_data (&object->qdata, context->quark_notify_queue, NULL); if (n_pspecs) context->dispatcher (object, n_pspecs, pspecs); g_free (free_me); }
static gboolean gst_object_set_name_default (GstObject * object) { const gchar *type_name; gint count; gchar *name, *tmp; gboolean result; GQuark q; /* to ensure guaranteed uniqueness across threads, only one thread * may ever assign a name */ G_LOCK (object_name_mutex); if (!object_name_counts) { g_datalist_init (&object_name_counts); } q = g_type_qname (G_OBJECT_TYPE (object)); count = GPOINTER_TO_INT (g_datalist_id_get_data (&object_name_counts, q)); g_datalist_id_set_data (&object_name_counts, q, GINT_TO_POINTER (count + 1)); G_UNLOCK (object_name_mutex); /* GstFooSink -> foosinkN */ type_name = g_quark_to_string (q); if (strncmp (type_name, "Gst", 3) == 0) type_name += 3; tmp = g_strdup_printf ("%s%d", type_name, count); name = g_ascii_strdown (tmp, -1); g_free (tmp); result = gst_object_set_name (object, name); g_free (name); return result; }
void _tarif_rebuild(gint tarif_id, GSList ** tarif) { gchar *cmd = NULL; sqlite3_stmt *stmt = NULL; GSList *link = NULL; g_assert(tarif_id > 0 && tarif != NULL); _tarif_clear(tarif_id); cmd = sqlite3_mprintf("select id, days, stime, hourprice from tarifs\n" "where tarif = %d;", tarif_id); sqlite3_prepare(ccl->db, cmd, -1, &stmt, NULL); sqlite3_free(cmd); while (sqlite3_step(stmt) == SQLITE_ROW) { CCL_tarifpart *part = NULL; guint days = sqlite3_column_double(stmt, 1); guint hour = 0; guint min = 0; guint stime = 0; gint i; gchar *cmd2 = NULL; sqlite3_stmt *stmt2 = NULL; GData ** prices = g_malloc0(sizeof(GData *)); gint id = 0; id = sqlite3_column_int(stmt, 0); /* Load prices */ g_datalist_init(prices); cmd2 = sqlite3_mprintf("select mins, price from prices\n" "where tarifpart = %d;", id); sqlite3_prepare(ccl->db, cmd2, -1, &stmt2, NULL); sqlite3_free(cmd2); while (sqlite3_step(stmt2) == SQLITE_ROW) { gint mins; guint price; mins = sqlite3_column_int(stmt2, 0); price = sqlite3_column_double(stmt2, 1); g_datalist_id_set_data(prices, mins, GINT_TO_POINTER(price)); } sqlite3_finalize(stmt2); /* Add tarifpart */ sscanf((gchar *) sqlite3_column_text(stmt, 2), "%u:%u", &hour, &min); stime = hour * 60 + min; for (i = 0; i < 7; i++) { if ((1 << i) & days) { part = g_new0(CCL_tarifpart, 1); part->stime = stime + i * 24 * 60; part->id = sqlite3_column_int(stmt, 0); part->hprice = sqlite3_column_double(stmt, 3); part->prices = prices; *tarif = g_slist_insert_sorted(*tarif, part, _TarifCompareFunc); } } } sqlite3_finalize(stmt); /* Now i am going to remove unnessesary links to clean things */ link = *tarif; while (link) { GSList *nextlink = g_slist_next(link); CCL_tarifpart *part = (CCL_tarifpart *) link->data; if (!nextlink) link = NULL; else if (((CCL_tarifpart *) nextlink->data)->id == part->id) { *tarif = g_slist_remove_link(*tarif, nextlink); g_free(nextlink->data); nextlink->data = NULL; g_slist_free_1(nextlink); } else link = nextlink; } /* If the first link in the list does not start on sunday at 00:00 * * insert the last one there, so things don't broke on calculation */ if (*tarif && 0 != ((CCL_tarifpart *) (*tarif)->data)->stime) { CCL_tarifpart *newpart = g_new0(CCL_tarifpart, 1); CCL_tarifpart *lastpart = NULL; GSList *link = *tarif; while (link->next) link = link->next; lastpart = (CCL_tarifpart *) link->data; newpart->id = lastpart->id; newpart->hprice = lastpart->hprice; newpart->stime = 0; newpart->prices = lastpart->prices; *tarif = g_slist_prepend(*tarif, newpart); } /* add it to the list */ g_datalist_id_set_data(&ccl->tarifs, tarif_id, *tarif); }
/****************************************************** * gst_v4l2_empty_lists() and gst_v4l2_fill_lists(): * fill/empty the lists of enumerations * return value: TRUE on success, FALSE on error ******************************************************/ static gboolean gst_v4l2_fill_lists (GstV4l2Object * v4l2object) { gint n, next; struct v4l2_queryctrl control = { 0, }; GstElement *e; e = v4l2object->element; GST_DEBUG_OBJECT (e, "getting enumerations"); GST_V4L2_CHECK_OPEN (v4l2object); GST_DEBUG_OBJECT (e, " channels"); /* and now, the channels */ for (n = 0;; n++) { struct v4l2_input input; GstV4l2TunerChannel *v4l2channel; GstTunerChannel *channel; memset (&input, 0, sizeof (input)); input.index = n; if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_ENUMINPUT, &input) < 0) { if (errno == EINVAL || errno == ENOTTY) break; /* end of enumeration */ else { GST_ELEMENT_ERROR (e, RESOURCE, SETTINGS, (_("Failed to query attributes of input %d in device %s"), n, v4l2object->videodev), ("Failed to get %d in input enumeration for %s. (%d - %s)", n, v4l2object->videodev, errno, strerror (errno))); return FALSE; } } GST_LOG_OBJECT (e, " index: %d", input.index); GST_LOG_OBJECT (e, " name: '%s'", input.name); GST_LOG_OBJECT (e, " type: %08x", input.type); GST_LOG_OBJECT (e, " audioset: %08x", input.audioset); GST_LOG_OBJECT (e, " std: %016" G_GINT64_MODIFIER "x", (guint64) input.std); GST_LOG_OBJECT (e, " status: %08x", input.status); v4l2channel = g_object_new (GST_TYPE_V4L2_TUNER_CHANNEL, NULL); channel = GST_TUNER_CHANNEL (v4l2channel); channel->label = g_strdup ((const gchar *) input.name); channel->flags = GST_TUNER_CHANNEL_INPUT; v4l2channel->index = n; if (input.type == V4L2_INPUT_TYPE_TUNER) { struct v4l2_tuner vtun; v4l2channel->tuner = input.tuner; channel->flags |= GST_TUNER_CHANNEL_FREQUENCY; vtun.index = input.tuner; if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_G_TUNER, &vtun) < 0) { GST_ELEMENT_ERROR (e, RESOURCE, SETTINGS, (_("Failed to get setting of tuner %d on device '%s'."), input.tuner, v4l2object->videodev), GST_ERROR_SYSTEM); g_object_unref (G_OBJECT (channel)); return FALSE; } channel->freq_multiplicator = 62.5 * ((vtun.capability & V4L2_TUNER_CAP_LOW) ? 1 : 1000); channel->min_frequency = vtun.rangelow * channel->freq_multiplicator; channel->max_frequency = vtun.rangehigh * channel->freq_multiplicator; channel->min_signal = 0; channel->max_signal = 0xffff; } if (input.audioset) { /* we take the first. We don't care for * the others for now */ while (!(input.audioset & (1 << v4l2channel->audio))) v4l2channel->audio++; channel->flags |= GST_TUNER_CHANNEL_AUDIO; } v4l2object->channels = g_list_prepend (v4l2object->channels, (gpointer) channel); } v4l2object->channels = g_list_reverse (v4l2object->channels); GST_DEBUG_OBJECT (e, " norms"); /* norms... */ for (n = 0;; n++) { struct v4l2_standard standard = { 0, }; GstV4l2TunerNorm *v4l2norm; GstTunerNorm *norm; /* fill in defaults */ standard.frameperiod.numerator = 1; standard.frameperiod.denominator = 0; standard.index = n; if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_ENUMSTD, &standard) < 0) { if (errno == EINVAL || errno == ENOTTY) break; /* end of enumeration */ #ifdef ENODATA else if (errno == ENODATA) break; /* end of enumeration, as of Linux 3.7-rc1 */ #endif else { GST_ELEMENT_ERROR (e, RESOURCE, SETTINGS, (_("Failed to query norm on device '%s'."), v4l2object->videodev), ("Failed to get attributes for norm %d on devide '%s'. (%d - %s)", n, v4l2object->videodev, errno, strerror (errno))); return FALSE; } } GST_DEBUG_OBJECT (e, " '%s', fps: %d / %d", standard.name, standard.frameperiod.denominator, standard.frameperiod.numerator); v4l2norm = g_object_new (GST_TYPE_V4L2_TUNER_NORM, NULL); norm = GST_TUNER_NORM (v4l2norm); norm->label = g_strdup ((const gchar *) standard.name); gst_value_set_fraction (&norm->framerate, standard.frameperiod.denominator, standard.frameperiod.numerator); v4l2norm->index = standard.id; GST_DEBUG_OBJECT (v4l2object->element, "index=%08x, label=%s", (unsigned int) v4l2norm->index, norm->label); v4l2object->norms = g_list_prepend (v4l2object->norms, (gpointer) norm); } v4l2object->norms = g_list_reverse (v4l2object->norms); GST_DEBUG_OBJECT (e, " controls+menus"); /* and lastly, controls+menus (if appropriate) */ next = V4L2_CTRL_FLAG_NEXT_CTRL; n = 0; control.id = next; while (TRUE) { GstV4l2ColorBalanceChannel *v4l2channel; GstColorBalanceChannel *channel; if (!next) n++; retry: /* when we reached the last official CID, continue with private CIDs */ if (n == V4L2_CID_LASTP1) { GST_DEBUG_OBJECT (e, "checking private CIDs"); n = V4L2_CID_PRIVATE_BASE; } GST_DEBUG_OBJECT (e, "checking control %08x", n); control.id = n | next; if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_QUERYCTRL, &control) < 0) { if (next) { if (n > 0) { GST_DEBUG_OBJECT (e, "controls finished"); break; } else { GST_DEBUG_OBJECT (e, "V4L2_CTRL_FLAG_NEXT_CTRL not supported."); next = 0; n = V4L2_CID_BASE; goto retry; } } if (errno == EINVAL || errno == ENOTTY || errno == EIO || errno == ENOENT) { if (n < V4L2_CID_PRIVATE_BASE) { GST_DEBUG_OBJECT (e, "skipping control %08x", n); /* continue so that we also check private controls */ n = V4L2_CID_PRIVATE_BASE - 1; continue; } else { GST_DEBUG_OBJECT (e, "controls finished"); break; } } else { GST_WARNING_OBJECT (e, "Failed querying control %d on device '%s'. " "(%d - %s)", n, v4l2object->videodev, errno, strerror (errno)); continue; } } /* bogus driver might mess with id in unexpected ways (e.g. set to 0), so * make sure to simply try all if V4L2_CTRL_FLAG_NEXT_CTRL not supported */ if (next) n = control.id; if (control.flags & V4L2_CTRL_FLAG_DISABLED) { GST_DEBUG_OBJECT (e, "skipping disabled control"); continue; } if (control.type == V4L2_CTRL_TYPE_CTRL_CLASS) { GST_DEBUG_OBJECT (e, "starting control class '%s'", control.name); continue; } switch (control.type) { case V4L2_CTRL_TYPE_INTEGER: case V4L2_CTRL_TYPE_BOOLEAN: case V4L2_CTRL_TYPE_MENU: case V4L2_CTRL_TYPE_INTEGER_MENU: case V4L2_CTRL_TYPE_BITMASK: case V4L2_CTRL_TYPE_BUTTON:{ control.name[31] = '\0'; gst_v4l2_normalise_control_name ((gchar *) control.name); g_datalist_id_set_data (&v4l2object->controls, g_quark_from_string ((const gchar *) control.name), GINT_TO_POINTER (n)); break; } default: GST_DEBUG_OBJECT (e, "Control type for '%s' not suppored for extra controls.", control.name); break; } switch (n) { case V4L2_CID_BRIGHTNESS: case V4L2_CID_CONTRAST: case V4L2_CID_SATURATION: case V4L2_CID_HUE: case V4L2_CID_BLACK_LEVEL: case V4L2_CID_AUTO_WHITE_BALANCE: case V4L2_CID_DO_WHITE_BALANCE: case V4L2_CID_RED_BALANCE: case V4L2_CID_BLUE_BALANCE: case V4L2_CID_GAMMA: case V4L2_CID_EXPOSURE: case V4L2_CID_AUTOGAIN: case V4L2_CID_GAIN: case V4L2_CID_SHARPNESS: /* we only handle these for now (why?) */ break; case V4L2_CID_HFLIP: case V4L2_CID_VFLIP: case V4L2_CID_PAN_RESET: case V4L2_CID_TILT_RESET: /* not handled here, handled by VideoOrientation interface */ control.id++; break; case V4L2_CID_AUDIO_VOLUME: case V4L2_CID_AUDIO_BALANCE: case V4L2_CID_AUDIO_BASS: case V4L2_CID_AUDIO_TREBLE: case V4L2_CID_AUDIO_MUTE: case V4L2_CID_AUDIO_LOUDNESS: /* FIXME: We should implement GstMixer interface instead */ /* but let's not be pedantic and make element more useful for now */ break; case V4L2_CID_ALPHA_COMPONENT: v4l2object->has_alpha_component = TRUE; break; default: GST_DEBUG_OBJECT (e, "ControlID %s (%x) unhandled, FIXME", control.name, n); control.id++; break; } if (n != control.id) continue; GST_DEBUG_OBJECT (e, "Adding ControlID %s (%x)", control.name, n); v4l2channel = g_object_new (GST_TYPE_V4L2_COLOR_BALANCE_CHANNEL, NULL); channel = GST_COLOR_BALANCE_CHANNEL (v4l2channel); channel->label = g_strdup ((const gchar *) control.name); v4l2channel->id = n; #if 0 /* FIXME: it will be need just when handling private controls *(currently none of base controls are of this type) */ if (control.type == V4L2_CTRL_TYPE_MENU) { struct v4l2_querymenu menu, *mptr; int i; menu.id = n; for (i = 0;; i++) { menu.index = i; if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_QUERYMENU, &menu) < 0) { if (errno == EINVAL) break; /* end of enumeration */ else { GST_ELEMENT_ERROR (e, RESOURCE, SETTINGS, (_("Failed getting controls attributes on device '%s'."), v4l2object->videodev), ("Failed to get %d in menu enumeration for %s. (%d - %s)", n, v4l2object->videodev, errno, strerror (errno))); return FALSE; } } mptr = g_malloc (sizeof (menu)); memcpy (mptr, &menu, sizeof (menu)); menus = g_list_append (menus, mptr); } } v4l2object->menus = g_list_append (v4l2object->menus, menus); #endif switch (control.type) { case V4L2_CTRL_TYPE_INTEGER: channel->min_value = control.minimum; channel->max_value = control.maximum; break; case V4L2_CTRL_TYPE_BOOLEAN: channel->min_value = FALSE; channel->max_value = TRUE; break; default: /* FIXME we should find out how to handle V4L2_CTRL_TYPE_BUTTON. BUTTON controls like V4L2_CID_DO_WHITE_BALANCE can just be set (1) or unset (0), but can't be queried */ GST_DEBUG_OBJECT (e, "Control with non supported type %s (%x), type=%d", control.name, n, control.type); channel->min_value = channel->max_value = 0; break; } v4l2object->colors = g_list_prepend (v4l2object->colors, (gpointer) channel); } v4l2object->colors = g_list_reverse (v4l2object->colors); GST_DEBUG_OBJECT (e, "done"); return TRUE; }
static void _set_name (GESTimelineElement * self, const gchar * wanted_name) { const gchar *type_name; gchar *lowcase_type; gint count; GQuark q; guint i, l; gchar *name = NULL; if (!object_name_counts) { g_datalist_init (&object_name_counts); } q = g_type_qname (G_OBJECT_TYPE (self)); count = GPOINTER_TO_INT (g_datalist_id_get_data (&object_name_counts, q)); /* GstFooSink -> foosink<N> */ type_name = g_quark_to_string (q); if (strncmp (type_name, "GES", 3) == 0) type_name += 3; lowcase_type = g_strdup (type_name); l = strlen (lowcase_type); for (i = 0; i < l; i++) lowcase_type[i] = g_ascii_tolower (lowcase_type[i]); if (wanted_name == NULL) { /* give the 20th "uriclip" element and the first "uriclip2" (if needed in the future) * different names */ l = strlen (type_name); if (l > 0 && g_ascii_isdigit (type_name[l - 1])) { name = g_strdup_printf ("%s-%d", lowcase_type, count++); } else { name = g_strdup_printf ("%s%d", lowcase_type, count++); } } else { /* If the wanted name uses the same 'namespace' as default, make * sure it does not badly interfere with our counting system */ if (g_str_has_prefix (wanted_name, lowcase_type)) { guint64 tmpcount = g_ascii_strtoull (&wanted_name[strlen (lowcase_type)], NULL, 10); if (tmpcount > count) { count = tmpcount + 1; GST_DEBUG_OBJECT (self, "Using same naming %s but updated count to %i", wanted_name, count); } else if (tmpcount < count) { name = g_strdup_printf ("%s%d", lowcase_type, count); count++; GST_DEBUG_OBJECT (self, "Name %s already allocated, giving: %s instead" " New count is %i", wanted_name, name, count); } else { count++; GST_DEBUG_OBJECT (self, "Perfect name, just bumping object count"); } } if (name == NULL) name = g_strdup (wanted_name); } g_free (lowcase_type); g_datalist_id_set_data (&object_name_counts, q, GINT_TO_POINTER (count)); g_free (self->name); self->name = name; }