static JSBool js_item_moveBefore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { js_item_t *ji = JS_GetPrivate(cx, obj); js_item_t *before; if(argc >= 1 && JSVAL_IS_OBJECT(argv[0]) && !JSVAL_IS_NULL(argv[0]) && JS_GetClass(cx, JSVAL_TO_OBJECT(argv[0])) == &item_class) { before = JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0])); } else { before = NULL; } TAILQ_REMOVE(&ji->ji_model->jm_items, ji, ji_link); if(before) TAILQ_INSERT_BEFORE(before, ji, ji_link); else TAILQ_INSERT_TAIL(&ji->ji_model->jm_items, ji, ji_link); prop_move(ji->ji_root, before ? before->ji_root : NULL); *rval = JSVAL_VOID; return JS_TRUE; }
static connman_service_t * update_service(GVariant *v, const char *path, connman_service_t *after) { connman_service_t *cs = connman_service_find(path); if(cs == NULL) { GError *err = NULL; GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START , NULL, "net.connman", path, "net.connman.Service", NULL, &err); if(proxy == NULL) { TRACE(TRACE_ERROR, "CONNMAN", "Unable to connect to service %s -- %s", path, err->message); g_error_free(err); return NULL; } cs = calloc(1, sizeof(connman_service_t)); cs->cs_refcount = 1; cs->cs_proxy = proxy; if(after == NULL) { TAILQ_INSERT_HEAD(&connman_services, cs, cs_link); } else { TAILQ_INSERT_AFTER(&connman_services, after, cs, cs_link); } connman_service_t *next = TAILQ_NEXT(cs, cs_link); cs->cs_prop = prop_create_root(path); cs->cs_path = strdup(path); cs->cs_sub = prop_subscribe(0, PROP_TAG_CALLBACK_EVENT, connman_service_event, cs, PROP_TAG_ROOT, cs->cs_prop, PROP_TAG_COURIER, connman_courier, NULL); g_signal_connect(G_OBJECT(cs->cs_proxy), "g-signal", G_CALLBACK(connman_svc_signal), cs); // Insert at correct position if(prop_set_parent_ex(cs->cs_prop, service_nodes, next ? next->cs_prop : NULL, NULL)) abort(); prop_t *m = prop_create(cs->cs_prop, "metadata"); prop_link(prop_create(m, "name"), prop_create(m, "title")); prop_set(cs->cs_prop, "type", PROP_SET_STRING, "network"); } else { // Possibly move TAILQ_REMOVE(&connman_services, cs, cs_link); if(after == NULL) { TAILQ_INSERT_HEAD(&connman_services, cs, cs_link); } else { TAILQ_INSERT_AFTER(&connman_services, after, cs, cs_link); } connman_service_t *next = TAILQ_NEXT(cs, cs_link); prop_move(cs->cs_prop, next ? next->cs_prop : NULL); } // Update metadata prop_set_from_vardict(v, prop_create(cs->cs_prop, "metadata")); GVariant *name = g_variant_lookup_value(v, "Name", NULL); const gchar *val = name ? g_variant_get_string(name, NULL) : NULL; if(val) mystrset(&cs->cs_name, val); return cs; }
static void htsp_channelAddUpdate(htsp_connection_t *hc, htsmsg_t *m, int create) { uint32_t id, next; int chnum; prop_t *p; char txt[200]; const char *title, *icon; htsp_channel_t *ch, *n; if(htsmsg_get_u32(m, "channelId", &id)) return; title = htsmsg_get_str(m, "channelName"); icon = htsmsg_get_str(m, "channelIcon"); chnum = htsmsg_get_s32_or_default(m, "channelNumber", -1); if(chnum == 0) chnum = INT32_MAX; snprintf(txt, sizeof(txt), "%d", id); hts_mutex_lock(&hc->hc_meta_mutex); if(create) { ch = calloc(1, sizeof(htsp_channel_t)); p = ch->ch_root = prop_create_root(txt); prop_t *m = prop_create(p, "metadata"); ch->ch_prop_icon = prop_create(m, "icon"); ch->ch_prop_title = prop_create(m, "title"); ch->ch_prop_channelNumber = prop_create(m, "channelNumber"); ch->ch_prop_events = prop_create(m, "events"); ch->ch_id = id; snprintf(txt, sizeof(txt), "htsp://%s:%d/channel/%d", hc->hc_hostname, hc->hc_port, id); prop_set_string(prop_create(p, "url"), txt); prop_set_string(prop_create(p, "type"), "tvchannel"); ch->ch_channel_num = chnum; mystrset(&ch->ch_title, title); TAILQ_INSERT_SORTED(&hc->hc_channels, ch, ch_link, channel_compar); n = TAILQ_NEXT(ch, ch_link); if(prop_set_parent_ex(p, hc->hc_channels_nodes, n ? n->ch_root : NULL, NULL)) abort(); } else { int move = 0; ch = htsp_channel_get(hc, id); if(ch == NULL) { TRACE(TRACE_ERROR, "HTSP", "Got update for unknown channel %d", id); hts_mutex_unlock(&hc->hc_meta_mutex); return; } p = ch->ch_root; if(title != NULL) { move = 1; mystrset(&ch->ch_title, title); } if(chnum != -1) { move = 1; ch->ch_channel_num = chnum; } if(move) { TAILQ_REMOVE(&hc->hc_channels, ch, ch_link); TAILQ_INSERT_SORTED(&hc->hc_channels, ch, ch_link, channel_compar); n = TAILQ_NEXT(ch, ch_link); prop_move(p, n ? n->ch_root : NULL); } } hts_mutex_unlock(&hc->hc_meta_mutex); if(icon != NULL) prop_set_string(ch->ch_prop_icon, icon); if(title != NULL) prop_set_string(ch->ch_prop_title, title); if(chnum != -1) prop_set_int(ch->ch_prop_channelNumber, chnum); if(htsmsg_get_u32(m, "eventId", &id)) id = 0; if(htsmsg_get_u32(m, "nextEventId", &next)) next = 0; update_events(hc, ch->ch_prop_events, id, next); }