/** * gs_plugin_key_colors_set_for_pixbuf: */ static void gs_plugin_key_colors_set_for_pixbuf (GsApp *app, GdkPixbuf *pb, guint number) { GList *l; gint rowstride, n_channels; gint x, y; guchar *pixels, *p; guint bin_size = 200; guint i; guint number_of_bins; g_autoptr(AsImage) im = NULL; /* go through each pixel */ n_channels = gdk_pixbuf_get_n_channels (pb); rowstride = gdk_pixbuf_get_rowstride (pb); pixels = gdk_pixbuf_get_pixels (pb); for (bin_size = 250; bin_size > 0; bin_size -= 2) { g_autoptr(GHashTable) hash = NULL; hash = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); for (y = 0; y < gdk_pixbuf_get_height (pb); y++) { for (x = 0; x < gdk_pixbuf_get_width (pb); x++) { CdColorRGB8 tmp; GsColorBin *s; gpointer key; /* disregard any with alpha */ p = pixels + y * rowstride + x * n_channels; if (p[3] != 255) continue; /* find in cache */ tmp.R = p[0] / bin_size; tmp.G = p[1] / bin_size; tmp.B = p[2] / bin_size; key = GUINT_TO_POINTER (cd_color_rgb8_to_uint32 (&tmp)); s = g_hash_table_lookup (hash, key); if (s != NULL) { s->color.red += p[0]; s->color.green += p[1]; s->color.blue += p[2]; s->cnt++; continue; } /* add to hash table */ s = g_new0 (GsColorBin, 1); s->color.red = p[0]; s->color.green = p[1]; s->color.blue = p[2]; s->color.alpha = 1.0; s->cnt = 1; g_hash_table_insert (hash, key, s); } } number_of_bins = g_hash_table_size (hash); // g_debug ("number of colors: %i", number_of_bins); if (number_of_bins >= number) { g_autoptr(GList) values = NULL; /* order by most popular */ values = g_hash_table_get_values (hash); values = g_list_sort (values, gs_color_bin_sort_cb); for (l = values; l != NULL; l = l->next) { GsColorBin *s = l->data; g_autofree GdkRGBA *color = g_new0 (GdkRGBA, 1); color->red = s->color.red / s->cnt; color->green = s->color.green / s->cnt; color->blue = s->color.blue / s->cnt; gs_app_add_key_color (app, color); } return; } } /* the algorithm failed, so just return a monochrome ramp */ for (i = 0; i < 3; i++) { g_autofree GdkRGBA *color = g_new0 (GdkRGBA, 1); color->red = 255 * i / 3; color->green = color->red; color->blue = color->red; color->alpha = 1.0f; gs_app_add_key_color (app, color); } }
GList * lrm_state_get_list(void) { return g_hash_table_get_values(lrm_state_table); }
GList* connection_get_available_resources(void) { return g_hash_table_get_values(conn.available_resources); }
API bool connectClientSocketAsync(Socket *s, int timeout) { if(s->connected) { logError("Cannot connect already connected socket %d", s->fd); return false; } if(s->type != SOCKET_CLIENT) { logError("Cannot asynchronously connect non-client socket"); return false; } struct addrinfo hints; struct addrinfo *server; int ret; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; // don't care if we use IPv4 or IPv6 to reach our destination hints.ai_socktype = SOCK_STREAM; // TCP stream sockets if((ret = getaddrinfo(s->host, s->port, &hints, &server)) != 0) { logError("Failed to look up address %s:%s: %s", s->host, s->port, gai_strerror(ret)); return false; } if((s->fd = socket(server->ai_family, server->ai_socktype, server->ai_protocol)) == -1) { logSystemError("Failed to create socket"); return false; } if(!setSocketNonBlocking(s->fd)) { logSystemError("Failed to set socket non-blocking"); closeSocket(s); return false; } logNotice("Asynchronously connecting client socket %d to %s:%s...", s->fd, s->host, s->port); if(connect(s->fd, server->ai_addr, server->ai_addrlen) < 0) { // try to connect socket #ifdef WIN32 if(WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() == WSAEWOULDBLOCK) { #else if(errno == EINPROGRESS) { #endif // free previous timer if present free(s->custom); AsyncConnectionTimer *timer = ALLOCATE_OBJECT(AsyncConnectionTimer); timer->creationTime = getMicroTime(); timer->timeout = timeout; s->custom = timer; g_queue_push_tail(connecting, s); // add to connecting list logInfo("Socket %d delayed connection, queueing...", s->fd); } else { #ifdef WIN32 char *error = g_win32_error_message(WSAGetLastError()); logError("Connection for socket %d failed: %s", s->fd, error); free(error); #else logSystemError("Connection for socket %d failed", s->fd); #endif closeSocket(s); freeaddrinfo(server); return false; } } else { logNotice("Direct response for asynchronous connection on socket %d", s->fd); s->connected = true; triggerEvent(s, "connected"); enableSocketPolling(s); } freeaddrinfo(server); return true; } API bool enableSocketPolling(Socket *socket) { if(isSocketPollingEnabled(socket)) { // Socket with that fd is already polled return false; } int *fd = ALLOCATE_OBJECT(int); *fd = socket->fd; g_hash_table_insert(poll_table, fd, socket); return true; } API bool isSocketPollingEnabled(Socket *socket) { return g_hash_table_lookup(poll_table, &socket->fd) != NULL; } API bool disableSocketPolling(Socket *socket) { return g_hash_table_remove(poll_table, &socket->fd) == true; } API void pollSockets() { if(!polling) { polling = true; // set polling flag to lock our poll table in order to make this function reentrancy safe if(!g_queue_is_empty(connecting)) { GQueue *connectingSockets = g_queue_copy(connecting); // copy the connecting socket list so we may modify the list while polling for(GList *iter = connectingSockets->head; iter != NULL; iter = iter->next) { if(pollConnectingSocket(iter->data)) { // poll the connecting socket // The socket should no longer be polled g_queue_remove(connecting, iter->data); // remove it from the original connecting queue } } g_queue_free(connectingSockets); // remove our temporary iteration list } GList *sockets = g_hash_table_get_values(poll_table); // get a static list of sockets so we may modify the hash table while polling for(GList *iter = sockets; iter != NULL; iter = iter->next) { Socket *poll = iter->data; int fd; // storage for the file descriptor that won't be available anymore in case the socket gets freed before we remove it if(pollSocket(poll, &fd)) { // poll the socket // The socket should no longer be polled g_hash_table_remove(poll_table, &fd); // remove it from the polling table } } g_list_free(sockets); // remove our temporary iteration list polling = false; // release pseudo lock on poll table } } API bool isSocketsPolling() { return polling; } API Socket *getPolledSocketByFd(int fd) { return g_hash_table_lookup(poll_table, &fd); } /** * Callback to poll all sockets signed up for polling */ TIMER_CALLBACK(poll) { pollSockets(); triggerEvent(NULL, "sockets_polled"); TIMER_ADD_TIMEOUT(pollInterval, poll); } /** * Polls a connecting socket and notifies the caller of whether it should be removed from the connecting polling queue afterwards * * @param socket the connecting socket to poll * @result true if the socket should be removed from the connecting polling queue after polling */ static bool pollConnectingSocket(Socket *socket) { assert(!socket->connected); assert(socket->type == SOCKET_CLIENT); assert(socket->custom != NULL); // Check whether the socket has timed out yet AsyncConnectionTimer *timer = socket->custom; if(getMicroTime() - timer->creationTime > timer->timeout) { // connection timed out logWarning("Asynchronous connection on socket %d timed out", socket->fd); closeSocket(socket); triggerEvent(socket, "disconnect"); return true; } // Initialize timeout struct timeval tv = {0, 0}; // Initialize write fd set fd_set fdset; FD_ZERO(&fdset); FD_SET(socket->fd, &fdset); // Select socket for write flag (connected) int ret; if((ret = select(socket->fd + 1, NULL, &fdset, NULL, &tv)) < 0) { #ifdef WIN32 if(WSAGetLastError() != WSAEINTR) { char *error = g_win32_error_message(WSAGetLastError()); logError("Error selecting socket %d for write flag (connected) while polling: %s", socket->fd, error); free(error); #else if(errno != EINTR) { logSystemError("Error selecting socket %d for write flag (connected) while polling", socket->fd); #endif closeSocket(socket); triggerEvent(socket, "disconnect"); return true; } // EINTR at this point means the socket is just not connected yet, so we can safely return and continue polling another time return false; } else if(ret > 0) { // there is a write flag on the socket // Socket selected for write, check if we're indeed connected int valopt; socklen_t lon = sizeof(int); if(getsockopt(socket->fd, SOL_SOCKET, SO_ERROR, (void*) (&valopt), &lon) < 0) { logSystemError("getsockopt() failed on socket %d", socket->fd); closeSocket(socket); triggerEvent(socket, "disconnect"); return true; } else if(valopt != 0) { // There was a connection error logSystemError("Asynchronous connection on socket %d failed", socket->fd); closeSocket(socket); triggerEvent(socket, "disconnect"); return true; } logNotice("Asynchronously connected socket %d", socket->fd); socket->connected = true; triggerEvent(socket, "connected"); enableSocketPolling(socket); return true; } // the socket doesn't have a write flag, so let's just wait until it's connected return false; } /** * Polls a socket and notifies the caller of whether it should be removed from the polling table afterwards * * @param socket the socket to poll * @param fd_p a pointer to an integer field to which the file descriptor of the socket should be written in case the socket should be removed from the polling table and could already be freed at that time * @result true if the socket should be removed from the polling table after polling */ static bool pollSocket(Socket *socket, int *fd_p) { *fd_p = socket->fd; // backup file descriptor if(!socket->connected) { // Socket is disconnected triggerEvent(socket, "disconnect"); return true; } if(socket->type != SOCKET_SERVER && socket->type != SOCKET_SERVER_BLOCK) { int ret; if((ret = socketReadRaw(socket, poll_buffer, SOCKET_POLL_BUFSIZE)) < 0) { if(socket->connected) { // socket is still connected, so the error was not fatal triggerEvent(socket, "error"); return false; } else { // socket was disconnected either by the peer or by a fatal error triggerEvent(socket, "disconnect"); return true; } } else if(ret > 0) { // we actually read something triggerEvent(socket, "read", poll_buffer, ret); } // else nothing to read right now } else { Socket *clientSocket; if((clientSocket = socketAccept(socket)) != NULL) { triggerEvent(socket, "accept", clientSocket); } else { if(socket->connected) { // socket is still connected, so the error was not fatal triggerEvent(socket, "error"); return false; } else { // socket was disconnected either by the peer or by a fatal error triggerEvent(socket, "disconnect"); return true; } } } return false; }
/* Plugin implementation */ int janus_streaming_init(janus_callbacks *callback, const char *config_path) { if(stopping) { /* Still stopping from before */ return -1; } if(callback == NULL || config_path == NULL) { /* Invalid arguments */ return -1; } /* Read configuration */ char filename[255]; sprintf(filename, "%s/%s.cfg", config_path, JANUS_STREAMING_PACKAGE); JANUS_LOG(LOG_VERB, "Configuration file: %s\n", filename); janus_config *config = janus_config_parse(filename); if(config != NULL) janus_config_print(config); mountpoints = g_hash_table_new(NULL, NULL); /* Parse configuration to populate the mountpoints */ if(config != NULL) { janus_config_category *cat = janus_config_get_categories(config); while(cat != NULL) { if(cat->name == NULL) { cat = cat->next; continue; } JANUS_LOG(LOG_VERB, "Adding stream '%s'\n", cat->name); janus_config_item *type = janus_config_get_item(cat, "type"); if(type == NULL || type->value == NULL) { JANUS_LOG(LOG_VERB, " -- Invalid type, skipping stream...\n"); cat = cat->next; continue; } if(!strcasecmp(type->value, "rtp")) { /* RTP live source (e.g., from gstreamer/ffmpeg/vlc/etc.) */ janus_config_item *id = janus_config_get_item(cat, "id"); janus_config_item *desc = janus_config_get_item(cat, "description"); janus_config_item *audio = janus_config_get_item(cat, "audio"); janus_config_item *video = janus_config_get_item(cat, "video"); janus_config_item *aport = janus_config_get_item(cat, "audioport"); janus_config_item *acodec = janus_config_get_item(cat, "audiopt"); janus_config_item *artpmap = janus_config_get_item(cat, "audiortpmap"); janus_config_item *vport = janus_config_get_item(cat, "videoport"); janus_config_item *vcodec = janus_config_get_item(cat, "videopt"); janus_config_item *vrtpmap = janus_config_get_item(cat, "videortpmap"); janus_streaming_mountpoint *live_rtp = calloc(1, sizeof(janus_streaming_mountpoint)); if(live_rtp == NULL) { JANUS_LOG(LOG_FATAL, "Memory error!\n"); continue; } if(id == NULL || id->value == NULL) { JANUS_LOG(LOG_ERR, "Can't add 'rtp' stream, missing mandatory information...\n"); cat = cat->next; continue; } gboolean doaudio = audio && audio->value && !strcasecmp(audio->value, "yes"); gboolean dovideo = video && video->value && !strcasecmp(video->value, "yes"); if(!doaudio && !dovideo) { JANUS_LOG(LOG_ERR, "Can't add 'rtp' stream, no audio or video have to be streamed...\n"); g_free(live_rtp); cat = cat->next; continue; } if(doaudio && (aport == NULL || aport->value == NULL || acodec == NULL || acodec->value == NULL || artpmap == NULL || artpmap->value == NULL)) { JANUS_LOG(LOG_ERR, "Can't add 'rtp' stream, missing mandatory information for audio...\n"); cat = cat->next; continue; } if(dovideo && (vport == NULL || vport->value == NULL || vcodec == NULL || vcodec->value == NULL || vrtpmap == NULL || vrtpmap->value == NULL)) { JANUS_LOG(LOG_ERR, "Can't add 'rtp' stream, missing mandatory information for video...\n"); cat = cat->next; continue; } JANUS_LOG(LOG_VERB, "Audio %s, Video %s\n", doaudio ? "enabled" : "NOT enabled", dovideo ? "enabled" : "NOT enabled"); live_rtp->name = g_strdup(cat->name); live_rtp->id = atoi(id->value); char *description = NULL; if(desc != NULL && desc->value != NULL) description = g_strdup(desc->value); else description = g_strdup(cat->name); live_rtp->description = description; live_rtp->active = FALSE; live_rtp->streaming_type = janus_streaming_type_live; live_rtp->streaming_source = janus_streaming_source_rtp; janus_streaming_rtp_source *live_rtp_source = calloc(1, sizeof(janus_streaming_rtp_source)); if(live_rtp->name == NULL || description == NULL || live_rtp_source == NULL) { JANUS_LOG(LOG_FATAL, "Memory error!\n"); if(live_rtp->name) g_free(live_rtp->name); if(description) g_free(description); if(live_rtp_source); g_free(live_rtp_source); g_free(live_rtp); continue; } live_rtp_source->audio_port = doaudio ? atoi(aport->value) : -1; live_rtp_source->video_port = dovideo ? atoi(vport->value) : -1; live_rtp->source = live_rtp_source; live_rtp->codecs.audio_pt = doaudio ? atoi(acodec->value) : -1; live_rtp->codecs.audio_rtpmap = doaudio ? g_strdup(artpmap->value) : NULL; live_rtp->codecs.video_pt = dovideo ? atoi(vcodec->value) : -1; live_rtp->codecs.video_rtpmap = dovideo ? g_strdup(vrtpmap->value) : NULL; live_rtp->listeners = NULL; g_hash_table_insert(mountpoints, GINT_TO_POINTER(live_rtp->id), live_rtp); g_thread_new(live_rtp->name, &janus_streaming_relay_thread, live_rtp); } else if(!strcasecmp(type->value, "live")) { /* a-Law file live source */ janus_config_item *id = janus_config_get_item(cat, "id"); janus_config_item *desc = janus_config_get_item(cat, "description"); janus_config_item *file = janus_config_get_item(cat, "filename"); janus_config_item *audio = janus_config_get_item(cat, "audio"); janus_config_item *video = janus_config_get_item(cat, "video"); if(id == NULL || id->value == NULL || file == NULL || file->value == NULL) { JANUS_LOG(LOG_ERR, "Can't add 'live' stream, missing mandatory information...\n"); cat = cat->next; continue; } gboolean doaudio = audio && audio->value && !strcasecmp(audio->value, "yes"); gboolean dovideo = video && video->value && !strcasecmp(video->value, "yes"); /* TODO We should support something more than raw a-Law and mu-Law streams... */ if(!doaudio || dovideo) { JANUS_LOG(LOG_ERR, "Can't add 'live' stream, we only support audio file streaming right now...\n"); cat = cat->next; continue; } if(!strstr(file->value, ".alaw") && !strstr(file->value, ".mulaw")) { JANUS_LOG(LOG_ERR, "Can't add 'ondemand' stream, unsupported format (we only support raw mu-Law and a-Law files right now)\n"); cat = cat->next; continue; } janus_streaming_mountpoint *live_file = calloc(1, sizeof(janus_streaming_mountpoint)); if(live_file == NULL) { JANUS_LOG(LOG_FATAL, "Memory error!\n"); continue; } live_file->name = g_strdup(cat->name); live_file->id = atoi(id->value); char *description = NULL; if(desc != NULL && desc->value != NULL) description = g_strdup(desc->value); else description = g_strdup(cat->name); live_file->description = description; live_file->active = FALSE; live_file->streaming_type = janus_streaming_type_live; live_file->streaming_source = janus_streaming_source_file; janus_streaming_file_source *live_file_source = calloc(1, sizeof(janus_streaming_file_source)); if(live_file->name == NULL || description == NULL || live_file_source == NULL) { JANUS_LOG(LOG_FATAL, "Memory error!\n"); if(live_file->name) g_free(live_file->name); if(description) g_free(description); if(live_file_source); g_free(live_file_source); g_free(live_file); continue; } live_file_source->filename = g_strdup(file->value); live_file->source = live_file_source; live_file->codecs.audio_pt = strstr(file->value, ".alaw") ? 8 : 0; live_file->codecs.audio_rtpmap = strstr(file->value, ".alaw") ? "PCMA/8000" : "PCMU/8000"; live_file->codecs.video_pt = -1; /* FIXME We don't support video for this type yet */ live_file->codecs.video_rtpmap = NULL; live_file->listeners = NULL; g_hash_table_insert(mountpoints, GINT_TO_POINTER(live_file->id), live_file); g_thread_new(live_file->name, &janus_streaming_filesource_thread, live_file); } else if(!strcasecmp(type->value, "ondemand")) { /* mu-Law file on demand source */ janus_config_item *id = janus_config_get_item(cat, "id"); janus_config_item *desc = janus_config_get_item(cat, "description"); janus_config_item *file = janus_config_get_item(cat, "filename"); janus_config_item *audio = janus_config_get_item(cat, "audio"); janus_config_item *video = janus_config_get_item(cat, "video"); if(id == NULL || id->value == NULL || file == NULL || file->value == NULL) { JANUS_LOG(LOG_ERR, "Can't add 'ondemand' stream, missing mandatory information...\n"); cat = cat->next; continue; } gboolean doaudio = audio && audio->value && !strcasecmp(audio->value, "yes"); gboolean dovideo = video && video->value && !strcasecmp(video->value, "yes"); /* TODO We should support something more than raw a-Law and mu-Law streams... */ if(!doaudio || dovideo) { JANUS_LOG(LOG_ERR, "Can't add 'ondemand' stream, we only support audio file streaming right now...\n"); cat = cat->next; continue; } if(!strstr(file->value, ".alaw") && !strstr(file->value, ".mulaw")) { JANUS_LOG(LOG_ERR, "Can't add 'ondemand' stream, unsupported format (we only support raw mu-Law and a-Law files right now)\n"); cat = cat->next; continue; } janus_streaming_mountpoint *ondemand_file = calloc(1, sizeof(janus_streaming_mountpoint)); if(ondemand_file == NULL) { JANUS_LOG(LOG_FATAL, "Memory error!\n"); continue; } ondemand_file->name = g_strdup(cat->name); ondemand_file->id = atoi(id->value); char *description = NULL; if(desc != NULL && desc->value != NULL) description = g_strdup(desc->value); else description = g_strdup(cat->name); ondemand_file->description = description; ondemand_file->active = FALSE; ondemand_file->streaming_type = janus_streaming_type_on_demand; ondemand_file->streaming_source = janus_streaming_source_file; janus_streaming_file_source *ondemand_file_source = calloc(1, sizeof(janus_streaming_file_source)); if(ondemand_file->name == NULL || description == NULL || ondemand_file_source == NULL) { JANUS_LOG(LOG_FATAL, "Memory error!\n"); if(ondemand_file->name) g_free(ondemand_file->name); if(description) g_free(description); if(ondemand_file_source); g_free(ondemand_file_source); g_free(ondemand_file); continue; } ondemand_file_source->filename = g_strdup(file->value); ondemand_file->source = ondemand_file_source; ondemand_file->codecs.audio_pt = strstr(file->value, ".alaw") ? 8 : 0; ondemand_file->codecs.audio_rtpmap = strstr(file->value, ".alaw") ? "PCMA/8000" : "PCMU/8000"; ondemand_file->codecs.video_pt = -1; /* FIXME We don't support video for this type yet */ ondemand_file->codecs.video_rtpmap = NULL; ondemand_file->listeners = NULL; g_hash_table_insert(mountpoints, GINT_TO_POINTER(ondemand_file->id), ondemand_file); } cat = cat->next; } /* Done */ janus_config_destroy(config); config = NULL; } /* Show available mountpoints */ GList *mountpoints_list = g_hash_table_get_values(mountpoints); GList *m = mountpoints_list; while(m) { janus_streaming_mountpoint *mp = (janus_streaming_mountpoint *)m->data; JANUS_LOG(LOG_VERB, " ::: [%"SCNu64"][%s] %s (%s, %s)\n", mp->id, mp->name, mp->description, mp->streaming_type == janus_streaming_type_live ? "live" : "on demand", mp->streaming_source == janus_streaming_source_rtp ? "RTP source" : "file source"); m = m->next; } g_list_free(mountpoints_list); sessions = g_hash_table_new(NULL, NULL); janus_mutex_init(&sessions_mutex); messages = g_queue_new(); /* This is the callback we'll need to invoke to contact the gateway */ gateway = callback; initialized = 1; /* Launch the thread that will handle incoming messages */ GError *error = NULL; handler_thread = g_thread_try_new("janus streaming handler", janus_streaming_handler, NULL, &error); if(error != NULL) { initialized = 0; /* Something went wrong... */ JANUS_LOG(LOG_ERR, "Got error %d (%s) trying to launch thread...\n", error->code, error->message ? error->message : "??"); return -1; } JANUS_LOG(LOG_INFO, "%s initialized!\n", JANUS_STREAMING_NAME); return 0; }
xmpp_unknown_items(unknown_tree, tvb, pinfo, child, 1); proto_item_append_text(unknown_item, " [UNKNOWN]"); expert_add_info_format(pinfo, unknown_item, &ei_xmpp_unknown_element, "Unknown element: %s", child->name); } childs = childs->next; } } void xmpp_unknown_attrs(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, xmpp_element_t *element, gboolean displ_short_list) { proto_item *item = proto_tree_get_parent(tree); GList *keys = g_hash_table_get_keys(element->attrs); GList *values = g_hash_table_get_values(element->attrs); GList *keys_head = keys, *values_head = values; gboolean short_list_started = FALSE; while(keys && values) { xmpp_attr_t *attr = (xmpp_attr_t*) values->data; if (!attr->was_read) { if (displ_short_list) { if (!short_list_started) proto_item_append_text(item, " ["); else proto_item_append_text(item, " "); proto_item_append_text(item, "%s=\"%s\"", (gchar*) keys->data, attr->value);
void dacp_share_ctrl_int (DMAPShare * share, SoupServer * server, SoupMessage * message, const char *path, GHashTable * query, SoupClientContext * context) { const char *rest_of_path; DACPShare *dacp_share = DACP_SHARE (share); g_debug ("Path is %s.", path); if (query) { g_hash_table_foreach (query, debug_param, NULL); } rest_of_path = strchr (path + 1, '/'); /* If calling /ctrl-int without args, the client doesnt need a * session-id, otherwise it does and it should be validated. */ if ((rest_of_path != NULL) && (!_dmap_share_session_id_validate (share, context, message, query, NULL))) { soup_message_set_status (message, SOUP_STATUS_FORBIDDEN); return; } if (rest_of_path == NULL) { /* CACI control-int * MSTT status * MUTY update type * MTCO specified total count * MRCO returned count * MLCL listing * MLIT listing item * MIID item id * CMIK Unknown (TRUE) * CMSP Unknown (TRUE) * CMSV Unknown (TRUE) * CASS Unknown (TRUE) * CASU Unknown (TRUE) * CASG Unknown (TRUE) */ GNode *caci; GNode *mlcl; GNode *mlit; // dacp.controlint caci = dmap_structure_add (NULL, DMAP_CC_CACI); // dmap.status dmap_structure_add (caci, DMAP_CC_MSTT, (gint32) DMAP_STATUS_OK); // dmap.updatetype dmap_structure_add (caci, DMAP_CC_MUTY, 0); // dmap.specifiedtotalcount dmap_structure_add (caci, DMAP_CC_MTCO, (gint32) 1); // dmap.returnedcount dmap_structure_add (caci, DMAP_CC_MRCO, (gint32) 1); // dmap.listing mlcl = dmap_structure_add (caci, DMAP_CC_MLCL); // dmap.listingitem mlit = dmap_structure_add (mlcl, DMAP_CC_MLIT); // dmap.itemid dmap_structure_add (mlit, DMAP_CC_MIID, (gint32) 1); // Unknown (TRUE) dmap_structure_add (mlit, DMAP_CC_CMIK, (gint32) 1); // Unknown (TRUE) dmap_structure_add (mlit, DMAP_CC_CMSP, (gint32) 1); // Unknown (TRUE) dmap_structure_add (mlit, DMAP_CC_CMSV, (gint32) 1); // Unknown (TRUE) dmap_structure_add (mlit, DMAP_CC_CASS, (gint32) 1); // Unknown (TRUE) dmap_structure_add (mlit, DMAP_CC_CASU, (gint32) 1); // Unknown (TRUE) dmap_structure_add (mlit, DMAP_CC_CASG, (gint32) 1); _dmap_share_message_set_from_dmap_structure (share, message, caci); dmap_structure_destroy (caci); } else if (g_ascii_strcasecmp ("/1/getproperty", rest_of_path) == 0) { gchar *properties_query, **properties, **property; GNode *cmgt; properties_query = g_hash_table_lookup (query, "properties"); if (!properties_query) { g_warning ("No property specified"); return; } cmgt = dmap_structure_add (NULL, DMAP_CC_CMGT); dmap_structure_add (cmgt, DMAP_CC_MSTT, DMAP_STATUS_OK); properties = g_strsplit (properties_query, ",", -1); for (property = properties; *property; property++) { if (g_ascii_strcasecmp (*property, "dmcp.volume") == 0) { gulong volume; g_object_get (dacp_share->priv->player, "volume", &volume, NULL); //g_debug ("Sending volume: %lu", volume); dmap_structure_add (cmgt, DMAP_CC_CMVO, volume); } else { g_warning ("Unhandled property %s", *property); } } g_strfreev (properties); _dmap_share_message_set_from_dmap_structure (share, message, cmgt); dmap_structure_destroy (cmgt); } else if (g_ascii_strcasecmp ("/1/setproperty", rest_of_path) == 0) { if (g_hash_table_lookup (query, "dmcp.volume")) { gdouble volume = strtod (g_hash_table_lookup (query, "dmcp.volume"), NULL); g_object_set (dacp_share->priv->player, "volume", (gulong) volume, NULL); } soup_message_set_status (message, SOUP_STATUS_NO_CONTENT); } else if (g_ascii_strcasecmp ("/1/getspeakers", rest_of_path) == 0) { GNode *casp; casp = dmap_structure_add (NULL, DMAP_CC_CASP); dmap_structure_add (casp, DMAP_CC_MSTT, (gint32) DMAP_STATUS_OK); dmap_structure_add (casp, DMAP_CC_MDCL); dmap_structure_add (casp, DMAP_CC_CAIA, TRUE); dmap_structure_add (casp, DMAP_CC_MINM, "Computer"); dmap_structure_add (casp, DMAP_CC_MSMA, (gint32) 0); _dmap_share_message_set_from_dmap_structure (share, message, casp); dmap_structure_destroy (casp); } else if (g_ascii_strcasecmp ("/1/playstatusupdate", rest_of_path) == 0) { gchar *revision = g_hash_table_lookup (query, "revision-number"); gint revision_number = atoi (revision); if (revision_number >= dacp_share->priv->current_revision) { g_object_ref (message); dacp_share->priv->update_queue = g_slist_prepend (dacp_share-> priv->update_queue, message); g_signal_connect_object (message, "finished", G_CALLBACK (status_update_message_finished), dacp_share, 0); soup_server_pause_message (server, message); } else { dacp_share_fill_playstatusupdate (dacp_share, message); } } else if (g_ascii_strcasecmp ("/1/playpause", rest_of_path) == 0) { dacp_player_play_pause (dacp_share->priv->player); soup_message_set_status (message, SOUP_STATUS_NO_CONTENT); } else if (g_ascii_strcasecmp ("/1/pause", rest_of_path) == 0) { dacp_player_pause (dacp_share->priv->player); soup_message_set_status (message, SOUP_STATUS_NO_CONTENT); } else if (g_ascii_strcasecmp ("/1/nextitem", rest_of_path) == 0) { dacp_player_next_item (dacp_share->priv->player); soup_message_set_status (message, SOUP_STATUS_NO_CONTENT); } else if (g_ascii_strcasecmp ("/1/previtem", rest_of_path) == 0) { dacp_player_prev_item (dacp_share->priv->player); soup_message_set_status (message, SOUP_STATUS_NO_CONTENT); } else if (g_ascii_strcasecmp ("/1/nowplayingartwork", rest_of_path) == 0) { guint width = 320; guint height = 320; gchar *artwork_filename; gchar *buffer; gsize buffer_len; if (g_hash_table_lookup (query, "mw")) width = atoi (g_hash_table_lookup (query, "mw")); if (g_hash_table_lookup (query, "mh")) height = atoi (g_hash_table_lookup (query, "mh")); artwork_filename = dacp_player_now_playing_artwork (dacp_share-> priv->player, width, height); if (!artwork_filename) { g_debug ("No artwork for currently playing song"); soup_message_set_status (message, SOUP_STATUS_NOT_FOUND); return; } #ifdef HAVE_GDKPIXBUF GdkPixbuf *artwork = gdk_pixbuf_new_from_file_at_scale (artwork_filename, width, height, TRUE, NULL); if (!artwork) { g_debug ("Error loading image file"); g_free (artwork_filename); soup_message_set_status (message, SOUP_STATUS_INTERNAL_SERVER_ERROR); return; } if (!gdk_pixbuf_save_to_buffer (artwork, &buffer, &buffer_len, "png", NULL, NULL)) { g_debug ("Error saving artwork to PNG"); g_object_unref (artwork); g_free (artwork_filename); soup_message_set_status (message, SOUP_STATUS_INTERNAL_SERVER_ERROR); return; } g_object_unref (artwork); #else if (!g_file_get_contents (artwork_filename, &buffer, &buffer_len, NULL)) { g_debug ("Error getting artwork data"); g_free (artwork_filename); soup_message_set_status (message, SOUP_STATUS_INTERNAL_SERVER_ERROR); return; } #endif g_free (artwork_filename); soup_message_set_status (message, SOUP_STATUS_OK); soup_message_set_response (message, "image/png", SOUP_MEMORY_TAKE, buffer, buffer_len); } else if (g_ascii_strcasecmp ("/1/cue", rest_of_path) == 0) { gchar *command; command = g_hash_table_lookup (query, "command"); if (!command) { g_debug ("No CUE command specified"); soup_message_set_status (message, SOUP_STATUS_NO_CONTENT); return; } else if (g_ascii_strcasecmp ("clear", command) == 0) { dacp_player_cue_clear (dacp_share->priv->player); soup_message_set_status (message, SOUP_STATUS_NO_CONTENT); } else if (g_ascii_strcasecmp ("play", command) == 0) { GNode *cacr; gchar *record_query; gchar *sort_by; GHashTable *records; GList *sorted_records; GSList *filter_def; DMAPDb *db; gint index = atoi (g_hash_table_lookup (query, "index")); g_object_get (share, "db", &db, NULL); record_query = g_hash_table_lookup (query, "query"); filter_def = _dmap_share_build_filter (record_query); records = dmap_db_apply_filter (db, filter_def); sorted_records = g_hash_table_get_values (records); sort_by = g_hash_table_lookup (query, "sort"); if (g_strcmp0 (sort_by, "album") == 0) { sorted_records = g_list_sort_with_data (sorted_records, (GCompareDataFunc) daap_record_cmp_by_album, db); } else if (sort_by != NULL) { g_warning ("Unknown sort column: %s", sort_by); } dacp_player_cue_play (dacp_share->priv->player, sorted_records, index); g_list_free (sorted_records); g_hash_table_unref (records); dmap_share_free_filter (filter_def); cacr = dmap_structure_add (NULL, DMAP_CC_CACR); dmap_structure_add (cacr, DMAP_CC_MSTT, DMAP_STATUS_OK); dmap_structure_add (cacr, DMAP_CC_MIID, index); _dmap_share_message_set_from_dmap_structure (share, message, cacr); dmap_structure_destroy (cacr); } else { g_warning ("Unhandled cue command: %s", command); soup_message_set_status (message, SOUP_STATUS_NO_CONTENT); return; } } else { g_warning ("Unhandled ctrl-int command: %s", rest_of_path); soup_message_set_status (message, SOUP_STATUS_BAD_REQUEST); } }
static connman_bool_t technology_apply_rfkill_change(struct connman_technology *technology, connman_bool_t softblock, connman_bool_t hardblock, connman_bool_t new_rfkill) { gboolean hardblock_changed = FALSE; gboolean apply = TRUE; GList *start, *list; DBG("technology %p --> %d/%d vs %d/%d", technology, softblock, hardblock, technology->softblocked, technology->hardblocked); if (technology->hardblocked == hardblock) goto softblock_change; if (!(new_rfkill == TRUE && hardblock == FALSE)) { start = g_hash_table_get_values(rfkill_list); for (list = start; list != NULL; list = list->next) { struct connman_rfkill *rfkill = list->data; if (rfkill->type != technology->type) continue; if (rfkill->hardblock != hardblock) apply = FALSE; } g_list_free(start); } if (apply == FALSE) goto softblock_change; technology->hardblocked = hardblock; hardblock_changed = TRUE; softblock_change: if (apply == FALSE && technology->softblocked != softblock) apply = TRUE; if (apply == FALSE) return technology->hardblocked; technology->softblocked = softblock; if (technology->hardblocked == TRUE || technology->softblocked == TRUE) { if (technology_disabled(technology) != -EALREADY) technology_affect_devices(technology, FALSE); } else if (technology->hardblocked == FALSE && technology->softblocked == FALSE) { if (technology_enabled(technology) != -EALREADY) technology_affect_devices(technology, TRUE); } if (hardblock_changed == TRUE) { if (technology->hardblocked == TRUE) { DBG("%s is switched off.", get_name(technology->type)); technology_dbus_unregister(technology); } else technology_dbus_register(technology); } return technology->hardblocked; }
static GList * get_places_list (void) { GList *list, *l; GHashTable *places; Place *place, *old_place; GList *places_list; places = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, NULL, (GDestroyNotify) place_free); /* add home */ place = g_slice_new0 (Place); place->location = g_file_new_for_path (g_get_home_dir ()); place->place_type = PLACE_XDG; place->display_name = g_strdup (_("Home")); g_hash_table_insert (places, place->location, place); /* first, load the XDG dirs */ list = get_xdg_dirs (); for (l = list; l != NULL; l = l->next) { place = l->data; g_hash_table_insert (places, place->location, place); } g_list_free (list); /* then, insert all the tracker locations that are not XDG dirs */ list = get_tracker_locations (); for (l = list; l != NULL; l = l->next) { place = l->data; old_place = g_hash_table_lookup (places, place->location); if (old_place == NULL) g_hash_table_insert (places, place->location, place); else place_free (place); } g_list_free (list); /* finally, load bookmarks, and possibly update attributes */ list = get_bookmarks (); for (l = list; l != NULL; l = l->next) { place = l->data; old_place = g_hash_table_lookup (places, place->location); if (old_place == NULL) { g_hash_table_insert (places, place->location, place); } else { g_free (old_place->display_name); old_place->display_name = g_strdup (place->display_name); if (old_place->place_type == PLACE_OTHER) old_place->place_type = PLACE_BOOKMARKS; place_free (place); } } g_list_free (list); places_list = g_hash_table_get_values (places); g_hash_table_steal_all (places); g_hash_table_unref (places); return places_list; }
static GList * _jabber_get_available_resources(void) { return g_hash_table_get_values(available_resources); }
static void update_device_list (GtkTreeIter *parent) { GtkUIManager *uimanager; GtkTreeIter iter; gboolean cont; guint num_devices; GList *actions, *l; num_devices = 0; uimanager = GTK_UI_MANAGER (gtk_builder_get_object (xml, "bluetooth-applet-ui-manager")); if (parent == NULL) { /* No default adapter? Remove everything */ actions = gtk_action_group_list_actions (devices_action_group); g_list_foreach (actions, (GFunc) remove_action_item, uimanager); g_list_free (actions); goto done; } /* Get a list of actions, and we'll remove the ones with a * device in the list. We remove the submenu items first */ actions = gtk_action_group_list_actions (devices_action_group); for (l = actions; l != NULL; l = l->next) { if (bluetooth_verify_address (gtk_action_get_name (l->data)) == FALSE) l->data = NULL; } actions = g_list_remove_all (actions, NULL); cont = gtk_tree_model_iter_children (devices_model, &iter, parent); while (cont) { GHashTable *services; DBusGProxy *proxy; char *alias, *address, **uuids, *name; gboolean is_connected; BluetoothType type; GtkAction *action, *status, *oper; gtk_tree_model_get (devices_model, &iter, BLUETOOTH_COLUMN_PROXY, &proxy, BLUETOOTH_COLUMN_ADDRESS, &address, BLUETOOTH_COLUMN_SERVICES, &services, BLUETOOTH_COLUMN_ALIAS, &alias, BLUETOOTH_COLUMN_UUIDS, &uuids, BLUETOOTH_COLUMN_TYPE, &type, -1); if (device_has_submenu ((const char **) uuids, services, type) == FALSE || address == NULL || proxy == NULL || alias == NULL) { if (proxy != NULL) g_object_unref (proxy); if (services != NULL) g_hash_table_unref (services); g_strfreev (uuids); g_free (alias); g_free (address); cont = gtk_tree_model_iter_next (devices_model, &iter); continue; } action = gtk_action_group_get_action (devices_action_group, address); oper = NULL; status = NULL; if (action) { char *action_name; actions = g_list_remove (actions, action); action_name = g_strdup_printf ("%s-status", address); status = gtk_action_group_get_action (devices_action_group, action_name); g_free (action_name); action_name = g_strdup_printf ("%s-action", address); oper = gtk_action_group_get_action (devices_action_group, action_name); g_free (action_name); } /* If one service is connected, then we're connected */ is_connected = FALSE; if (services != NULL) { GList *list, *l; list = g_hash_table_get_values (services); for (l = list; l != NULL; l = l->next) { BluetoothStatus val = GPOINTER_TO_INT (l->data); if (val == BLUETOOTH_STATUS_CONNECTED || val == BLUETOOTH_STATUS_PLAYING) { is_connected = TRUE; break; } } g_list_free (list); } name = escape_label_for_action (alias); if (action == NULL) { guint menu_merge_id; char *action_path; /* The menu item with descendants */ action = gtk_action_new (address, name, NULL, NULL); gtk_action_group_add_action (devices_action_group, action); g_object_unref (action); menu_merge_id = gtk_ui_manager_new_merge_id (uimanager); gtk_ui_manager_add_ui (uimanager, menu_merge_id, "/bluetooth-applet-popup/devices-placeholder", address, address, GTK_UI_MANAGER_MENU, FALSE); g_object_set_data_full (G_OBJECT (action), "merge-id", GUINT_TO_POINTER (menu_merge_id), NULL); /* The status menu item */ status = add_menu_item (address, "status", is_connected ? _("Connected") : _("Disconnected"), uimanager, menu_merge_id, NULL); gtk_action_set_sensitive (status, FALSE); if (services != NULL) { action_path = g_strdup_printf ("/bluetooth-applet-popup/devices-placeholder/%s/%s-status", address, address); action_set_bold (uimanager, status, action_path); g_free (action_path); } else { gtk_action_set_visible (status, FALSE); } /* The connect button */ oper = add_menu_item (address, "action", is_connected ? _("Disconnect") : _("Connect"), uimanager, menu_merge_id, G_CALLBACK (on_connect_activate)); if (services == NULL) gtk_action_set_visible (oper, FALSE); add_separator_item (address, "connect-sep", uimanager, menu_merge_id); /* The Send to... button */ if (device_has_uuid ((const char **) uuids, "OBEXObjectPush") != FALSE) { add_menu_item (address, "sendto", _("Send files..."), uimanager, menu_merge_id, G_CALLBACK (sendto_callback)); g_object_set_data_full (G_OBJECT (action), "alias", g_strdup (alias), g_free); } if (device_has_uuid ((const char **) uuids, "OBEXFileTransfer") != FALSE) { add_menu_item (address, "browse", _("Browse files..."), uimanager, menu_merge_id, G_CALLBACK (browse_callback)); } add_separator_item (address, "files-sep", uimanager, menu_merge_id); if (type == BLUETOOTH_TYPE_KEYBOARD && program_available (KEYBOARD_PREFS)) { add_menu_item (address, "keyboard", _("Open Keyboard Preferences..."), uimanager, menu_merge_id, G_CALLBACK (keyboard_callback)); } if (type == BLUETOOTH_TYPE_MOUSE && program_available (MOUSE_PREFS)) { add_menu_item (address, "mouse", _("Open Mouse Preferences..."), uimanager, menu_merge_id, G_CALLBACK (mouse_callback)); } if ((type == BLUETOOTH_TYPE_HEADSET || type == BLUETOOTH_TYPE_HEADPHONES || type == BLUETOOTH_TYPE_OTHER_AUDIO) && program_available (SOUND_PREFS)) { add_menu_item (address, "sound", _("Open Sound Preferences..."), uimanager, menu_merge_id, G_CALLBACK (sound_callback)); } } else { gtk_action_set_label (action, name); gtk_action_set_visible (status, services != NULL); gtk_action_set_visible (oper, services != NULL); if (services != NULL) { set_device_status_label (address, is_connected ? CONNECTED : DISCONNECTED); gtk_action_set_label (oper, is_connected ? _("Disconnect") : _("Connect")); } } g_free (name); if (oper != NULL) { g_object_set_data_full (G_OBJECT (oper), "connected", GINT_TO_POINTER (is_connected ? CONNECTED : DISCONNECTED), NULL); g_object_set_data_full (G_OBJECT (oper), "device-path", g_strdup (dbus_g_proxy_get_path (proxy)), g_free); } /* And now for the trick of the day */ if (is_connected != FALSE) { char *path; path = g_strdup_printf ("/bluetooth-applet-popup/devices-placeholder/%s", address); action_set_bold (uimanager, action, path); g_free (path); } num_devices++; if (proxy != NULL) g_object_unref (proxy); if (services != NULL) g_hash_table_unref (services); g_strfreev (uuids); g_free (alias); g_free (address); cont = gtk_tree_model_iter_next (devices_model, &iter); } /* Remove the left-over devices */ g_list_foreach (actions, (GFunc) remove_action_item, uimanager); g_list_free (actions); done: gtk_ui_manager_ensure_update (uimanager); gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (xml, "devices-label")), num_devices > 0); }
/** * gcr_union_collection_elements: * @self: the union collection * * Get the collections that have been added to this union. * * Returns: (element-type Gcr.Collection) (transfer container): collections * added to the union */ GList * gcr_union_collection_elements (GcrUnionCollection *self) { g_return_val_if_fail (GCR_IS_UNION_COLLECTION (self), NULL); return g_hash_table_get_values (self->pv->collections); }
/** \brief Create and run GtkSatModule popup menu. * \param module The module that should have the popup menu attached to it. * * This function ctreates and executes a popup menu that is related to a * GtkSatModule widget. The module must be a valid GtkSatModule, since it makes * no sense whatsoever to have this kind of popup menu without a GtkSatModule * parent. * */ void gtk_sat_module_popup (GtkSatModule *module) { GtkWidget *menu; /* The pop-up menu */ GtkWidget *satsubmenu; /* Satellite selection submenu */ GtkWidget *menuitem; /* Widget used to create the menu items */ GtkWidget *image; /* Widget used to create menu item icons */ /* misc variables */ GList *sats; sat_t *sat; gchar *buff; guint i,n; if ((module == NULL) || !IS_GTK_SAT_MODULE (module)) { sat_log_log (SAT_LOG_LEVEL_ERROR, _("%s:%d: %s called with NULL parameter!"), __FILE__, __LINE__, __FUNCTION__); return; } menu = gtk_menu_new (); if (module->state == GTK_SAT_MOD_STATE_DOCKED) { menuitem = gtk_image_menu_item_new_with_label (_("Detach module")); buff = icon_file_name ("gpredict-notebook.png"); image = gtk_image_new_from_file (buff); g_free (buff); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK (docking_state_cb), module); } else { menuitem = gtk_image_menu_item_new_with_label (_("Attach module")); buff = icon_file_name ("gpredict-notebook.png"); image = gtk_image_new_from_file (buff); g_free (buff); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK (docking_state_cb), module); } if (module->state == GTK_SAT_MOD_STATE_FULLSCREEN) { menuitem = gtk_image_menu_item_new_with_label (_("Exit full screen")); image = gtk_image_new_from_stock (GTK_STOCK_LEAVE_FULLSCREEN, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK (screen_state_cb), module); } else { menuitem = gtk_image_menu_item_new_with_label (_("Full screen")); image = gtk_image_new_from_stock (GTK_STOCK_FULLSCREEN, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK (screen_state_cb), module); } /* separator */ menuitem = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); /* select satellite submenu */ menuitem = gtk_menu_item_new_with_label(_("Select satellite")); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); satsubmenu = gtk_menu_new(); gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), satsubmenu); sats = g_hash_table_get_values(module->satellites); sats = g_list_sort(sats , (GCompareFunc) sat_nickname_compare ); n = g_list_length(sats); for (i = 0; i < n; i++) { sat = SAT(g_list_nth_data(sats, i)); menuitem = gtk_menu_item_new_with_label(sat->nickname); g_object_set_data(G_OBJECT(menuitem), "catnum", GINT_TO_POINTER(sat->tle.catnr)); g_signal_connect(menuitem, "activate", G_CALLBACK (sat_selected_cb), module); gtk_menu_shell_append(GTK_MENU_SHELL(satsubmenu), menuitem); } /* separator */ menuitem = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); /* sky at a glance */ menuitem = gtk_image_menu_item_new_with_label (_("Sky at a glance")); buff = icon_file_name ("gpredict-planner-small.png"); image = gtk_image_new_from_file (buff); g_free (buff); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK (sky_at_glance_cb), module); /* time manager */ menuitem = gtk_image_menu_item_new_with_label (_("Time Controller")); buff = icon_file_name ("gpredict-clock-small.png"); image = gtk_image_new_from_file (buff); g_free (buff); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK (tmgr_cb), module); /* separator */ menuitem = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); /* Radio Control */ menuitem = gtk_image_menu_item_new_with_label (_("Radio Control")); buff = icon_file_name ("gpredict-oscilloscope-small.png"); image = gtk_image_new_from_file (buff); g_free (buff); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK (rigctrl_cb), module); /* Antenna Control */ menuitem = gtk_image_menu_item_new_with_label (_("Antenna Control")); buff = icon_file_name ("gpredict-antenna-small.png"); image = gtk_image_new_from_file (buff); g_free (buff); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK (rotctrl_cb), module); /* separator */ menuitem = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); /* configure */ menuitem = gtk_image_menu_item_new_with_label (_("Configure")); image = gtk_image_new_from_stock (GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK (config_cb), module); /* clone */ menuitem = gtk_image_menu_item_new_with_label (_("Clone...")); image = gtk_image_new_from_stock (GTK_STOCK_COPY, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK (clone_cb), module); /* separator */ menuitem = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); /* delete module */ menuitem = gtk_image_menu_item_new_with_label (_("Delete")); image = gtk_image_new_from_stock (GTK_STOCK_DELETE, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK (delete_cb), module); /* close */ menuitem = gtk_image_menu_item_new_with_label (_("Close")); image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK (close_cb), module); gtk_widget_show_all (menu); gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 0, gdk_event_get_time (NULL)); }
// XXX step 2, basically the main function static int emit_package (lcmgen_t *lcm, _package_contents_t *pc) { // create the package directory, if necessary char **dirs = g_strsplit (pc->name, ".", 0); char *pdname = build_filenamev (dirs); char package_dir[PATH_MAX]; char package_dir_prefix[PATH_MAX]; int have_package = dirs[0] != NULL; sprintf (package_dir_prefix, "%s%s", getopt_get_string(lcm->gopt, "lpath"), strlen(getopt_get_string(lcm->gopt, "lpath")) > 0 ? G_DIR_SEPARATOR_S : ""); sprintf(package_dir, "%s%s%s", package_dir_prefix, pdname, have_package ? G_DIR_SEPARATOR_S : ""); free (pdname); if (strlen (package_dir)) { if (! g_file_test (package_dir, G_FILE_TEST_EXISTS)) { // g_mkdir_with_parents (package_dir, 0755); mkdir_with_parents (package_dir, 0755); } if (!g_file_test (package_dir, G_FILE_TEST_IS_DIR)) { err ("Could not create directory %s\n", package_dir); return -1; } } // write the package init.lua files, if necessary FILE *init_lua_fp = NULL; GHashTable * initlua_requires = NULL; GHashTable * initlua_requires_subpack = NULL; if (have_package) { int ndirs = 0; for (ndirs=0; dirs[ndirs]; ndirs++); for (int i=0 ; i<ndirs; i++) { // make filename char *initlua_fname; { char *initlua_fname_parts[1024]; assert(ndirs + 4 < 1024); initlua_fname_parts[0] = package_dir_prefix; for (int j=0; j<=i; j++) { initlua_fname_parts[j+1] = dirs[j]; } initlua_fname_parts[i+2] = "init.lua"; initlua_fname_parts[i+3] = NULL; initlua_fname = build_filenamev (initlua_fname_parts); } // make current package name char * package_name; { char * name_parts[1024]; assert(i < 1024); for (int j = 0; j <= i; j++) { name_parts[j] = dirs[j]; } name_parts[i + 1] = NULL; package_name = g_strjoinv(".", name_parts); } if (initlua_requires) { g_hash_table_destroy(initlua_requires); initlua_requires = NULL; } if (initlua_requires_subpack) { g_hash_table_destroy(initlua_requires_subpack); initlua_requires_subpack = NULL; } initlua_requires = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); initlua_requires_subpack = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); // if the file already exists, read the contents if (g_file_test (initlua_fname, G_FILE_TEST_EXISTS)) { init_lua_fp = fopen(initlua_fname, "r"); if (!init_lua_fp) { perror ("fopen"); free (initlua_fname); g_free(package_name); return -1; } while(!feof(init_lua_fp)) { char buf[4096]; memset(buf, 0, sizeof(buf)); char *result = fgets(buf, sizeof(buf)-1, init_lua_fp); if(!result) break; // XXX get all of the previous types and packages // this regex works because the first part is greedy GRegex * regex = g_regex_new("require\\('([\\w+\\.]*\\.)(\\w+)'\\)( -- subpackage)?", (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, NULL); GMatchInfo * matchinfo; if(g_regex_match(regex, buf, (GRegexMatchFlags) 0, &matchinfo)){ if(g_match_info_get_match_count(matchinfo) == 3){ // not a subpackage gchar * classname = g_match_info_fetch(matchinfo, 2); g_hash_table_insert(initlua_requires, g_strdup(classname), g_strdup(classname)); }else if(g_match_info_get_match_count(matchinfo) == 4){ // this is a subpackage // XXX fprintf(stderr, "> buff: %s\n", buf); gchar * superpackage = g_match_info_fetch(matchinfo, 1); gchar * subpackage = g_match_info_fetch(matchinfo, 2); // XXX fprintf(stderr, "> super: %s, sub: %s\n", superpackage, subpackage); gchar * fullsubpackage = g_strjoin("", superpackage, subpackage, NULL); // XXX fprintf(stderr, "> [2] inserting: %s\n", fullsubpackage); g_hash_table_insert(initlua_requires_subpack, g_strdup(fullsubpackage), g_strdup(fullsubpackage)); g_free(fullsubpackage); } } g_match_info_free(matchinfo); g_regex_unref(regex); } fclose(init_lua_fp); init_lua_fp = NULL; } init_lua_fp = fopen(initlua_fname, "w"); // XXX fprintf(stderr, "> opened: %s\n", initlua_fname); if (!init_lua_fp) { perror ("fopen"); free (initlua_fname); g_free(package_name); return -1; } #ifndef WIN32 // lock init.lua for exclusive write access // TODO do the equivalent in windows struct flock lockinfo; lockinfo.l_type = F_WRLCK; lockinfo.l_start = 0; lockinfo.l_whence = SEEK_SET; lockinfo.l_len = 0 ; lockinfo.l_pid = getpid(); if(0 != fcntl(fileno(init_lua_fp), F_SETLKW, &lockinfo)) { perror("locking init.lua"); free(initlua_fname); g_free(package_name); fclose(init_lua_fp); return -1; } #endif fprintf (init_lua_fp, "--[[\n" "LCM package init.lua file\n" "This file automatically generated by lcm-gen.\n" "DO NOT MODIFY BY HAND!!!!\n" "--]]\n" "\n" "local M = {}\n" "\n"); // add in all previous types GList * package_types = g_hash_table_get_values(initlua_requires); for (int j = 0; j < g_list_length(package_types); j++) { char * tn = (char *) g_list_nth_data(package_types, j); char * fn = g_strjoin(".", package_name, tn, NULL); fprintf(init_lua_fp, "M.%s = require('%s')\n", tn, fn); g_free(fn); } g_list_free(package_types); // add in all previous packages GList * subpacks = g_hash_table_get_values(initlua_requires_subpack); for (int j = 0; j < g_list_length(subpacks); j++) { char * spn = (char *) g_list_nth_data(subpacks, j); // get the base of the package name char ** tmpsplit = g_strsplit(spn, ".", -1); char * sn = tmpsplit[g_strv_length(tmpsplit) - 1]; // XXX fprintf(stderr, "[1] sn: %s, spn: %s\n", sn, spn); fprintf(init_lua_fp, "M.%s = require('%s') -- subpackage\n", sn, spn); g_strfreev(tmpsplit); } g_list_free(subpacks); // if the current package has a subpackage (which eventually contains the target package) // add a `require` for that subpackage to the current (if it hasn't already) if (i + 1 < ndirs) { char *subpack_name = g_strjoin(".", package_name, dirs[i + 1], NULL); // check for the subpackage name if (!g_hash_table_lookup(initlua_requires_subpack, subpack_name)) { // add it if it didn't exist g_hash_table_insert(initlua_requires_subpack, g_strdup(subpack_name), g_strdup(subpack_name)); // XXX fprintf(stderr, "[2] sn: %s, spn: %s\n", dirs[i + 1], subpack_name); fprintf(init_lua_fp, "M.%s = require('%s') -- subpackage\n", dirs[i + 1], subpack_name); } g_free(subpack_name); } // not yet the target? if (i + 1 < ndirs) { // close it out fprintf(init_lua_fp, "\nreturn M\n\n"); fclose(init_lua_fp); init_lua_fp = NULL; } free (initlua_fname); g_free(package_name); } } g_strfreev (dirs); //////////////////////////////////////////////////////////// // STRUCTS for (int i = 0; i<pc->structs->len; i++) { lcm_struct_t *ls = (lcm_struct_t *) g_ptr_array_index(pc->structs, i); char path[PATH_MAX]; sprintf (path, "%s%s.lua", package_dir, ls->structname->shortname); if(init_lua_fp){ // XXX add the 'require' to the appropriate init.lua if (!g_hash_table_lookup(initlua_requires, ls->structname->shortname)) { fprintf(init_lua_fp, "M.%s = require('%s')\n", ls->structname->shortname, ls->structname->lctypename); } // XXX look for subpackages for (unsigned int m = 0; m < g_ptr_array_size(ls->members); m++) { lcm_member_t *lm = (lcm_member_t *) g_ptr_array_index(ls->members, m); if(g_str_has_prefix(lm->type->package, pc->name)){ // make a regex starting with the current package... gchar ** tmpsplit = g_strsplit(pc->name, ".", 0); gchar * regexpackage = g_strjoinv("\\.", tmpsplit); // only look for immediate submodules, not submodules of the submodules gchar * regexstr = g_strjoin("", "^", regexpackage, "\\.(\\w+)", NULL); GRegex * regex = g_regex_new(regexstr, (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, NULL); GMatchInfo * matchinfo; g_strfreev(tmpsplit); g_free(regexpackage); g_free(regexstr); if (g_regex_match(regex, lm->type->package, (GRegexMatchFlags) 0, &matchinfo)) { if (g_match_info_get_match_count(matchinfo) == 2) { gchar * fullsubpackage = g_match_info_fetch(matchinfo, 0); gchar * subpackage = g_match_info_fetch(matchinfo, 1); // was it already in the file? if (!g_hash_table_lookup(initlua_requires_subpack, fullsubpackage)) { // XXX fprintf(stderr, "> [1] inserting: %s\n", fullsubpackage); g_hash_table_insert(initlua_requires_subpack, g_strdup(fullsubpackage), g_strdup(fullsubpackage)); fprintf(init_lua_fp, "M.%s = require('%s') -- subpackage\n", subpackage, fullsubpackage); } } } g_match_info_free(matchinfo); g_regex_unref(regex); } } } if (!lcm_needs_generation(lcm, ls->lcmfile, path)) continue; FILE *f = fopen(path, "w"); if (f==NULL) return -1; fprintf(f, "--[[\n" "LCM type definitions\n" "This file automatically generated by lcm.\n" "DO NOT MODIFY BY HAND!!!!\n" "--]]\n" "\n" "local lcm = require('lcm')\n\n"); emit_lua_dependencies (lcm, f, ls); // XXX added this... emit_lua_locals(lcm, f, ls); emit_lua_buffer_helper(lcm, f, ls); // XXX step 3, start making the object emit(0, "local %s = {}", ls->structname->shortname); emit(0, "%s.__index = %s", ls->structname->shortname, ls->structname->shortname); emit(0, ""); // CONSTANTS for (unsigned int cn = 0; cn < g_ptr_array_size(ls->constants); cn++) { lcm_constant_t *lc = (lcm_constant_t *) g_ptr_array_index(ls->constants, cn); assert(lcm_is_legal_const_type(lc->lctypename)); emit(1, "%s.%s = %s", ls->structname->shortname, lc->membername, lc->val_str); } if (g_ptr_array_size(ls->constants) > 0) emit(0, ""); // NAMES emit(0, "%s.name = '%s'", ls->structname->shortname, ls->structname->lctypename); emit(0, "%s.packagename = '%s'", ls->structname->shortname, ls->structname->package); emit(0, "%s.shortname = '%s'", ls->structname->shortname, ls->structname->shortname); emit(0, ""); emit_lua_new (lcm, f, ls); emit_lua_fingerprint (lcm, f, ls); emit_lua_encode (lcm, f, ls); emit_lua_encode_one (lcm, f, ls); emit_lua_decode (lcm, f, ls); emit_lua_decode_one (lcm, f, ls); emit(0, "return %s", ls->structname->shortname); emit(0, ""); fclose (f); } if(init_lua_fp){ fprintf(init_lua_fp, "\nreturn M\n\n"); fclose(init_lua_fp); } g_hash_table_destroy(initlua_requires); return 0; }
static GList* _slave_getAllHosts(Slave* slave) { MAGIC_ASSERT(slave); return g_hash_table_get_values(slave->hosts); }
void purple_media_stream_info(PurpleMedia *media, PurpleMediaInfoType type, const gchar *session_id, const gchar *participant, gboolean local) { #ifdef USE_VV g_return_if_fail(PURPLE_IS_MEDIA(media)); if (type == PURPLE_MEDIA_INFO_ACCEPT) { GList *streams, *sessions = NULL, *participants = NULL; g_return_if_fail(PURPLE_IS_MEDIA(media)); streams = purple_media_get_streams(media, session_id, participant); /* Emit stream acceptance */ for (; streams; streams = g_list_delete_link(streams, streams)) { PurpleMediaStream *stream = streams->data; stream->accepted = TRUE; g_signal_emit(media, purple_media_signals[STREAM_INFO], 0, type, stream->session->id, stream->participant, local); if (g_list_find(sessions, stream->session) == NULL) sessions = g_list_prepend(sessions, stream->session); if (g_list_find_custom(participants, stream->participant, (GCompareFunc)strcmp) == NULL) participants = g_list_prepend(participants, g_strdup(stream->participant)); } /* Emit session acceptance */ for (; sessions; sessions = g_list_delete_link(sessions, sessions)) { PurpleMediaSession *session = sessions->data; if (purple_media_accepted(media, session->id, NULL)) g_signal_emit(media, purple_media_signals[ STREAM_INFO], 0, PURPLE_MEDIA_INFO_ACCEPT, session->id, NULL, local); } /* Emit participant acceptance */ for (; participants; participants = g_list_delete_link( participants, participants)) { gchar *participant = participants->data; if (purple_media_accepted(media, NULL, participant)) g_signal_emit(media, purple_media_signals[ STREAM_INFO], 0, PURPLE_MEDIA_INFO_ACCEPT, NULL, participant, local); g_free(participant); } /* Emit conference acceptance */ if (purple_media_accepted(media, NULL, NULL)) g_signal_emit(media, purple_media_signals[STREAM_INFO], 0, PURPLE_MEDIA_INFO_ACCEPT, NULL, NULL, local); return; } else if (type == PURPLE_MEDIA_INFO_HANGUP || type == PURPLE_MEDIA_INFO_REJECT) { GList *streams; g_return_if_fail(PURPLE_IS_MEDIA(media)); streams = purple_media_get_streams(media, session_id, participant); /* Emit for stream */ for (; streams; streams = g_list_delete_link(streams, streams)) { PurpleMediaStream *stream = streams->data; g_signal_emit(media, purple_media_signals[STREAM_INFO], 0, type, stream->session->id, stream->participant, local); } if (session_id != NULL && participant != NULL) { /* Everything that needs to be emitted has been */ } else if (session_id == NULL && participant == NULL) { /* Emit for everything in the conference */ GList *sessions = NULL; GList *participants = media->priv->participants; if (media->priv->sessions != NULL) sessions = g_hash_table_get_values( media->priv->sessions); /* Emit for sessions */ for (; sessions; sessions = g_list_delete_link( sessions, sessions)) { PurpleMediaSession *session = sessions->data; g_signal_emit(media, purple_media_signals[ STREAM_INFO], 0, type, session->id, NULL, local); } /* Emit for participants */ for (; participants; participants = g_list_next(participants)) { gchar *participant = participants->data; g_signal_emit(media, purple_media_signals[ STREAM_INFO], 0, type, NULL, participant, local); } /* Emit for conference */ g_signal_emit(media, purple_media_signals[STREAM_INFO], 0, type, NULL, NULL, local); } else if (session_id != NULL) { /* Emit just the specific session */ PurpleMediaSession *session = purple_media_get_session( media, session_id); if (session == NULL) { purple_debug_warning("media", "Couldn't find session" " to hangup/reject.\n"); } else { g_signal_emit(media, purple_media_signals[ STREAM_INFO], 0, type, session->id, NULL, local); } } else if (participant != NULL) { /* Emit just the specific participant */ if (!g_list_find_custom(media->priv->participants, participant, (GCompareFunc)strcmp)) { purple_debug_warning("media", "Couldn't find participant" " to hangup/reject.\n"); } else { g_signal_emit(media, purple_media_signals[ STREAM_INFO], 0, type, NULL, participant, local); } } purple_media_end(media, session_id, participant); return; } g_signal_emit(media, purple_media_signals[STREAM_INFO], 0, type, session_id, participant, local); #endif }
static void reload_recent_items (GVfsBackendRecent *backend) { GVfsMonitor *monitor; GList *items; GList *node; GList *added = NULL; GList *changed = NULL; GList *not_seen_items = NULL; GList *l; not_seen_items = g_hash_table_get_values (backend->items); items = gtk_recent_manager_get_items (backend->recent_manager); for (node = items; node; node = node->next) { GtkRecentInfo *recent_info = node->data; const char *uri; const char *guid; if (!gtk_recent_info_is_local (recent_info) || gtk_recent_info_get_private_hint (recent_info) || g_strcmp0 (gtk_recent_info_get_mime_type (recent_info), "inode/directory") == 0) continue; uri = gtk_recent_info_get_uri (recent_info); guid = g_hash_table_lookup (backend->uri_map, uri); if (guid) { if (gtk_recent_info_exists (recent_info)) { RecentItem *item; item = g_hash_table_lookup (backend->items, guid); if (recent_item_update (item, recent_info)) changed = g_list_prepend (changed, item->guid); not_seen_items = g_list_remove (not_seen_items, item); } } else { RecentItem *item; item = recent_item_new (recent_info); added = g_list_prepend (added, item->guid); g_hash_table_insert (backend->items, item->guid, item); g_hash_table_insert (backend->uri_map, item->uri, item->guid); } gtk_recent_info_unref (recent_info); } g_list_free (items); monitor = recent_backend_get_dir_monitor (backend, FALSE); /* process removals */ for (l = not_seen_items; l; l = l->next) { RecentItem *item = l->data; g_hash_table_remove (backend->uri_map, item->uri); g_hash_table_steal (backend->items, item->guid); if (monitor) g_vfs_monitor_emit_event (monitor, G_FILE_MONITOR_EVENT_DELETED, item->guid, NULL); recent_item_free (item); } g_list_free (not_seen_items); /* process additions */ if (monitor) { for (l = added; l; l = l->next) g_vfs_monitor_emit_event (monitor, G_FILE_MONITOR_EVENT_CREATED, l->data, NULL); } g_list_free (added); /* process changes */ for (l = changed; l; l = l->next) { /* FIXME: signals */ } g_list_free (changed); if (monitor) g_object_unref (monitor); }
void dump_node_scores_worker(int level, const char *file, const char *function, int line, resource_t * rsc, const char *comment, GHashTable * nodes) { GHashTable *hash = nodes; GHashTableIter iter; node_t *node = NULL; if (rsc) { hash = rsc->allowed_nodes; } if (rsc && is_set(rsc->flags, pe_rsc_orphan)) { /* Don't show the allocation scores for orphans */ return; } if (level == 0) { /* For now we want this in sorted order to keep the regression tests happy */ GListPtr gIter = NULL; GListPtr list = g_hash_table_get_values(hash); list = g_list_sort(list, sort_node_uname); gIter = list; for (; gIter != NULL; gIter = gIter->next) { node_t *node = (node_t *) gIter->data; char *score = score2char(node->weight); if (rsc) { printf("%s: %s allocation score on %s: %s\n", comment, rsc->id, node->details->uname, score); } else { printf("%s: %s = %s\n", comment, node->details->uname, score); } free(score); } g_list_free(list); } else if (hash) { g_hash_table_iter_init(&iter, hash); while (g_hash_table_iter_next(&iter, NULL, (void **)&node)) { char *score = score2char(node->weight); if (rsc) { do_crm_log_alias(LOG_TRACE, file, function, line, "%s: %s allocation score on %s: %s", comment, rsc->id, node->details->uname, score); } else { do_crm_log_alias(LOG_TRACE, file, function, line + 1, "%s: %s = %s", comment, node->details->uname, score); } free(score); } } if (rsc && rsc->children) { GListPtr gIter = NULL; gIter = rsc->children; for (; gIter != NULL; gIter = gIter->next) { resource_t *child = (resource_t *) gIter->data; dump_node_scores_worker(level, file, function, line, child, comment, nodes); } } }
gboolean expand_notification_data(resource_t *rsc, notify_data_t * n_data, pe_working_set_t * data_set) { /* Expand the notification entries into a key=value hashtable * This hashtable is later used in action2xml() */ gboolean required = FALSE; char *rsc_list = NULL; char *node_list = NULL; char *metal_list = NULL; const char *source = NULL; GListPtr nodes = NULL; if (n_data->stop) { n_data->stop = g_list_sort(n_data->stop, sort_notify_entries); } expand_list(n_data->stop, &rsc_list, &node_list); if (rsc_list != NULL && safe_str_neq(" ", rsc_list)) { if (safe_str_eq(n_data->action, RSC_STOP)) { required = TRUE; } } add_notify_env_free(n_data, "notify_stop_resource", rsc_list); add_notify_env_free(n_data, "notify_stop_uname", node_list); if (n_data->start) { n_data->start = g_list_sort(n_data->start, sort_notify_entries); if (rsc_list && safe_str_eq(n_data->action, RSC_START)) { required = TRUE; } } expand_list(n_data->start, &rsc_list, &node_list); add_notify_env_free(n_data, "notify_start_resource", rsc_list); add_notify_env_free(n_data, "notify_start_uname", node_list); if (n_data->demote) { n_data->demote = g_list_sort(n_data->demote, sort_notify_entries); if (safe_str_eq(n_data->action, RSC_DEMOTE)) { required = TRUE; } } expand_list(n_data->demote, &rsc_list, &node_list); add_notify_env_free(n_data, "notify_demote_resource", rsc_list); add_notify_env_free(n_data, "notify_demote_uname", node_list); if (n_data->promote) { n_data->promote = g_list_sort(n_data->promote, sort_notify_entries); if (safe_str_eq(n_data->action, RSC_PROMOTE)) { required = TRUE; } } expand_list(n_data->promote, &rsc_list, &node_list); add_notify_env_free(n_data, "notify_promote_resource", rsc_list); add_notify_env_free(n_data, "notify_promote_uname", node_list); if (n_data->active) { n_data->active = g_list_sort(n_data->active, sort_notify_entries); } expand_list(n_data->active, &rsc_list, &node_list); add_notify_env_free(n_data, "notify_active_resource", rsc_list); add_notify_env_free(n_data, "notify_active_uname", node_list); if (n_data->slave) { n_data->slave = g_list_sort(n_data->slave, sort_notify_entries); } expand_list(n_data->slave, &rsc_list, &node_list); add_notify_env_free(n_data, "notify_slave_resource", rsc_list); add_notify_env_free(n_data, "notify_slave_uname", node_list); if (n_data->master) { n_data->master = g_list_sort(n_data->master, sort_notify_entries); } expand_list(n_data->master, &rsc_list, &node_list); add_notify_env_free(n_data, "notify_master_resource", rsc_list); add_notify_env_free(n_data, "notify_master_uname", node_list); if (n_data->inactive) { n_data->inactive = g_list_sort(n_data->inactive, sort_notify_entries); } expand_list(n_data->inactive, &rsc_list, NULL); add_notify_env_free(n_data, "notify_inactive_resource", rsc_list); nodes = g_hash_table_get_values(n_data->allowed_nodes); if (is_set(data_set->flags, pe_flag_stdout)) { /* If printing to stdout, sort the node list, for consistent * regression test output (while avoiding the performance hit * for the live cluster). */ nodes = g_list_sort(nodes, sort_node_uname); } expand_node_list(nodes, &node_list, NULL); add_notify_env_free(n_data, "notify_available_uname", node_list); g_list_free(nodes); source = g_hash_table_lookup(rsc->meta, XML_RSC_ATTR_TARGET); if (safe_str_eq("host", source)) { expand_node_list(data_set->nodes, &node_list, &metal_list); add_notify_env_free(n_data, "notify_all_hosts", metal_list); } else { expand_node_list(data_set->nodes, &node_list, NULL); } add_notify_env_free(n_data, "notify_all_uname", node_list); if (required && n_data->pre) { update_action_flags(n_data->pre, pe_action_optional | pe_action_clear, __FUNCTION__, __LINE__); update_action_flags(n_data->pre_done, pe_action_optional | pe_action_clear, __FUNCTION__, __LINE__); } if (required && n_data->post) { update_action_flags(n_data->post, pe_action_optional | pe_action_clear, __FUNCTION__, __LINE__); update_action_flags(n_data->post_done, pe_action_optional | pe_action_clear, __FUNCTION__, __LINE__); } return required; }
GList * xdk_display_list_windows(XdkDisplay * self) { g_return_val_if_fail(self, NULL); return g_hash_table_get_values(self->priv->windows); }
GList * seaf_clone_manager_get_tasks (SeafCloneManager *mgr) { return g_hash_table_get_values (mgr->tasks); }
void pocketvox_controller_on_request(PocketvoxController *controller, gpointer hyp, gpointer user_data) { GList *modules = NULL; gchar *request = (gchar *)hyp; gint i = 0, j = 0, n_threads; gdouble mindist = -1.0f, dist; GThreadPool *thread_pool = NULL; gboolean first_module = FALSE; g_return_if_fail(NULL != controller); g_return_if_fail(NULL != hyp); controller->priv = G_TYPE_INSTANCE_GET_PRIVATE (controller, TYPE_POCKETVOX_CONTROLLER, PocketvoxControllerPrivate); PocketvoxControllerPrivate *priv = controller->priv; gchar* window = pocketvox_xmanager_get_window(priv->xmanager); g_warning("WINDOW: %s", window); //put modules apps to activated g_hash_table_foreach(priv->modules, pocketvox_module_manage_apps, window); //make request //g_hash_table_foreach(priv->modules, pocketvox_module_make_request, request); modules = g_hash_table_get_values(priv->modules); n_threads = g_get_num_processors(); thread_pool = g_thread_pool_new((GFunc)pocketvox_module_threaded_request, request, n_threads, TRUE, NULL ); for(i = 0; i < g_list_length(modules); i++) { g_thread_pool_push(thread_pool, (PocketvoxModule *)g_list_nth_data(modules,i), NULL); } g_thread_pool_free(thread_pool, FALSE, TRUE); for(i = 0; i< g_list_length(modules); i++) { PocketvoxModule *module = g_list_nth_data(modules, i); dist = pocketvox_module_get_score(module); g_warning("%d %s %d %d %s %.5f", i, pocketvox_module_get_id(module), pocketvox_module_is_apps(module), pocketvox_module_get_activated(module), pocketvox_module_get_command(module), pocketvox_module_get_score(module)); if(pocketvox_module_get_activated(module) == TRUE && (dist < mindist || first_module==FALSE )) { mindist = dist; j = i; first_module = TRUE; } } PocketvoxModule *m = g_list_nth_data(modules, j); pocketvox_module_execute(m); g_list_free(modules); }
gboolean expand_notification_data(notify_data_t * n_data, pe_working_set_t * data_set) { /* Expand the notification entries into a key=value hashtable * This hashtable is later used in action2xml() */ gboolean required = FALSE; char *rsc_list = NULL; char *node_list = NULL; GListPtr nodes = NULL; if (n_data->stop) { n_data->stop = g_list_sort(n_data->stop, sort_notify_entries); } expand_list(n_data->stop, &rsc_list, &node_list); if (rsc_list != NULL && safe_str_neq(" ", rsc_list)) { if (safe_str_eq(n_data->action, RSC_STOP)) { required = TRUE; } } g_hash_table_insert(n_data->keys, strdup("notify_stop_resource"), rsc_list); g_hash_table_insert(n_data->keys, strdup("notify_stop_uname"), node_list); if (n_data->start) { n_data->start = g_list_sort(n_data->start, sort_notify_entries); if (rsc_list && safe_str_eq(n_data->action, RSC_START)) { required = TRUE; } } expand_list(n_data->start, &rsc_list, &node_list); g_hash_table_insert(n_data->keys, strdup("notify_start_resource"), rsc_list); g_hash_table_insert(n_data->keys, strdup("notify_start_uname"), node_list); if (n_data->demote) { n_data->demote = g_list_sort(n_data->demote, sort_notify_entries); if (safe_str_eq(n_data->action, RSC_DEMOTE)) { required = TRUE; } } expand_list(n_data->demote, &rsc_list, &node_list); g_hash_table_insert(n_data->keys, strdup("notify_demote_resource"), rsc_list); g_hash_table_insert(n_data->keys, strdup("notify_demote_uname"), node_list); if (n_data->promote) { n_data->promote = g_list_sort(n_data->promote, sort_notify_entries); if (safe_str_eq(n_data->action, RSC_PROMOTE)) { required = TRUE; } } expand_list(n_data->promote, &rsc_list, &node_list); g_hash_table_insert(n_data->keys, strdup("notify_promote_resource"), rsc_list); g_hash_table_insert(n_data->keys, strdup("notify_promote_uname"), node_list); if (n_data->active) { n_data->active = g_list_sort(n_data->active, sort_notify_entries); } expand_list(n_data->active, &rsc_list, &node_list); g_hash_table_insert(n_data->keys, strdup("notify_active_resource"), rsc_list); g_hash_table_insert(n_data->keys, strdup("notify_active_uname"), node_list); if (n_data->slave) { n_data->slave = g_list_sort(n_data->slave, sort_notify_entries); } expand_list(n_data->slave, &rsc_list, &node_list); g_hash_table_insert(n_data->keys, strdup("notify_slave_resource"), rsc_list); g_hash_table_insert(n_data->keys, strdup("notify_slave_uname"), node_list); if (n_data->master) { n_data->master = g_list_sort(n_data->master, sort_notify_entries); } expand_list(n_data->master, &rsc_list, &node_list); g_hash_table_insert(n_data->keys, strdup("notify_master_resource"), rsc_list); g_hash_table_insert(n_data->keys, strdup("notify_master_uname"), node_list); if (n_data->inactive) { n_data->inactive = g_list_sort(n_data->inactive, sort_notify_entries); } expand_list(n_data->inactive, &rsc_list, NULL); g_hash_table_insert(n_data->keys, strdup("notify_inactive_resource"), rsc_list); nodes = g_hash_table_get_values(n_data->allowed_nodes); node_list = expand_node_list(nodes); g_hash_table_insert(n_data->keys, strdup("notify_available_uname"), node_list); g_list_free(nodes); node_list = expand_node_list(data_set->nodes); g_hash_table_insert(n_data->keys, strdup("notify_all_uname"), node_list); if (required && n_data->pre) { update_action_flags(n_data->pre, pe_action_optional | pe_action_clear, __FUNCTION__); update_action_flags(n_data->pre_done, pe_action_optional | pe_action_clear, __FUNCTION__); } if (required && n_data->post) { update_action_flags(n_data->post, pe_action_optional | pe_action_clear, __FUNCTION__); update_action_flags(n_data->post_done, pe_action_optional | pe_action_clear, __FUNCTION__); } return required; }
static void SCPluginIfupdown_init (NMSystemConfigInterface *config) { SCPluginIfupdown *self = SC_PLUGIN_IFUPDOWN (config); SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (self); GHashTable *auto_ifaces; if_block *block = NULL; NMInotifyHelper *inotify_helper; GKeyFile* keyfile; GError *error = NULL; GList *keys, *iter; const char *subsys[2] = { "net", NULL }; auto_ifaces = g_hash_table_new (g_str_hash, g_str_equal); if(!priv->iface_connections) priv->iface_connections = g_hash_table_new (g_str_hash, g_str_equal); if(!priv->well_known_ifaces) priv->well_known_ifaces = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); if(!priv->well_known_interfaces) priv->well_known_interfaces = g_hash_table_new (g_str_hash, g_str_equal); PLUGIN_PRINT("SCPlugin-Ifupdown", "init!"); priv->client = g_udev_client_new (subsys); if (!priv->client) { PLUGIN_WARN ("SCPlugin-Ifupdown", " error initializing libgudev"); } else g_signal_connect (priv->client, "uevent", G_CALLBACK (handle_uevent), self); priv->unmanage_well_known = IFUPDOWN_UNMANAGE_WELL_KNOWN_DEFAULT; inotify_helper = nm_inotify_helper_get (); priv->inotify_event_id = g_signal_connect (inotify_helper, "event", G_CALLBACK (update_system_hostname), config); priv->inotify_system_hostname_wd = nm_inotify_helper_add_watch (inotify_helper, IFUPDOWN_SYSTEM_HOSTNAME_FILE); update_system_hostname (inotify_helper, NULL, NULL, config); /* Read in all the interfaces */ ifparser_init (ENI_INTERFACES_FILE, 0); block = ifparser_getfirst (); while (block) { if(!strcmp ("auto", block->type) || !strcmp ("allow-hotplug", block->type)) g_hash_table_insert (auto_ifaces, block->name, GUINT_TO_POINTER (1)); else if (!strcmp ("iface", block->type)) { NMIfupdownConnection *exported; /* Bridge configuration */ if(!strncmp ("br", block->name, 2)) { /* Try to find bridge ports */ const char *ports = ifparser_getkey (block, "bridge-ports"); if (ports) { int i; int state = 0; char **port_ifaces; PLUGIN_PRINT("SCPlugin-Ifupdown", "found bridge ports %s for %s", ports, block->name); port_ifaces = g_strsplit_set (ports, " \t", -1); for (i = 0; i < g_strv_length (port_ifaces); i++) { char *token = port_ifaces[i]; /* Skip crazy stuff like regex or all */ if (!strcmp ("all", token)) { continue; } /* Small SM to skip everything inside regex */ if (!strcmp ("regex", token)) { state++; continue; } if (!strcmp ("noregex", token)) { state--; continue; } if (state == 0 && strlen (token) > 0) { PLUGIN_PRINT("SCPlugin-Ifupdown", "adding bridge port %s to well_known_interfaces", token); g_hash_table_insert (priv->well_known_interfaces, g_strdup (token), "known"); } } g_strfreev (port_ifaces); } goto next; } /* Skip loopback configuration */ if(!strcmp ("lo", block->name)) { goto next; } /* Remove any connection for this block that was previously found */ exported = g_hash_table_lookup (priv->iface_connections, block->name); if (exported) { PLUGIN_PRINT("SCPlugin-Ifupdown", "deleting %s from iface_connections", block->name); nm_settings_connection_delete (NM_SETTINGS_CONNECTION (exported), ignore_cb, NULL); g_hash_table_remove (priv->iface_connections, block->name); } /* add the new connection */ exported = nm_ifupdown_connection_new (block); if (exported) { PLUGIN_PRINT("SCPlugin-Ifupdown", "adding %s to iface_connections", block->name); g_hash_table_insert (priv->iface_connections, block->name, exported); } PLUGIN_PRINT("SCPlugin-Ifupdown", "adding iface %s to well_known_interfaces", block->name); g_hash_table_insert (priv->well_known_interfaces, block->name, "known"); } else if (!strcmp ("mapping", block->type)) { g_hash_table_insert (priv->well_known_interfaces, block->name, "known"); PLUGIN_PRINT("SCPlugin-Ifupdown", "adding mapping %s to well_known_interfaces", block->name); } next: block = block->next; } /* Make 'auto' interfaces autoconnect=TRUE */ keys = g_hash_table_get_keys (priv->iface_connections); for (iter = keys; iter; iter = g_list_next (iter)) { NMIfupdownConnection *exported; NMSetting *setting; if (!g_hash_table_lookup (auto_ifaces, iter->data)) continue; exported = g_hash_table_lookup (priv->iface_connections, iter->data); setting = NM_SETTING (nm_connection_get_setting (NM_CONNECTION (exported), NM_TYPE_SETTING_CONNECTION)); g_object_set (setting, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NULL); nm_settings_connection_commit_changes (NM_SETTINGS_CONNECTION (exported), ignore_cb, NULL); PLUGIN_PRINT("SCPlugin-Ifupdown", "autoconnect"); } g_list_free (keys); g_hash_table_destroy (auto_ifaces); /* Find the config file */ if (g_file_test (IFUPDOWN_SYSTEM_SETTINGS_KEY_FILE, G_FILE_TEST_EXISTS)) priv->conf_file = IFUPDOWN_SYSTEM_SETTINGS_KEY_FILE; else priv->conf_file = IFUPDOWN_OLD_SYSTEM_SETTINGS_KEY_FILE; keyfile = g_key_file_new (); if (!g_key_file_load_from_file (keyfile, priv->conf_file, G_KEY_FILE_NONE, &error)) { nm_log_info (LOGD_SETTINGS, "loading system config file (%s) caused error: (%d) %s", priv->conf_file, error ? error->code : -1, error && error->message ? error->message : "(unknown)"); } else { gboolean manage_well_known; error = NULL; manage_well_known = g_key_file_get_boolean (keyfile, IFUPDOWN_KEY_FILE_GROUP, IFUPDOWN_KEY_FILE_KEY_MANAGED, &error); if (error) { nm_log_info (LOGD_SETTINGS, "getting keyfile key '%s' in group '%s' failed: (%d) %s", IFUPDOWN_KEY_FILE_GROUP, IFUPDOWN_KEY_FILE_KEY_MANAGED, error ? error->code : -1, error && error->message ? error->message : "(unknown)"); } else priv->unmanage_well_known = !manage_well_known; } PLUGIN_PRINT ("SCPluginIfupdown", "management mode: %s", priv->unmanage_well_known ? "unmanaged" : "managed"); if (keyfile) g_key_file_free (keyfile); /* Add well-known interfaces */ keys = g_udev_client_query_by_subsystem (priv->client, "net"); for (iter = keys; iter; iter = g_list_next (iter)) { udev_device_added (self, G_UDEV_DEVICE (iter->data)); g_object_unref (G_UDEV_DEVICE (iter->data)); } g_list_free (keys); /* Now if we're running in managed mode, let NM know there are new connections */ if (!priv->unmanage_well_known) { GList *con_list = g_hash_table_get_values (priv->iface_connections); GList *cl_iter; for (cl_iter = con_list; cl_iter; cl_iter = g_list_next (cl_iter)) { g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED, NM_SETTINGS_CONNECTION (cl_iter->data)); } g_list_free (con_list); } PLUGIN_PRINT("SCPlugin-Ifupdown", "end _init."); }
/* Thread to handle incoming messages */ static void *janus_streaming_handler(void *data) { JANUS_LOG(LOG_VERB, "Joining thread\n"); janus_streaming_message *msg = NULL; int error_code = 0; char *error_cause = calloc(1024, sizeof(char)); if(error_cause == NULL) { JANUS_LOG(LOG_FATAL, "Memory error!\n"); return NULL; } while(initialized && !stopping) { if(!messages || (msg = g_queue_pop_head(messages)) == NULL) { usleep(50000); continue; } janus_streaming_session *session = (janus_streaming_session *)msg->handle->plugin_handle; if(!session) { JANUS_LOG(LOG_ERR, "No session associated with this handle...\n"); janus_streaming_message_free(msg); continue; } if(session->destroy) { janus_streaming_message_free(msg); continue; } /* Handle request */ error_code = 0; JANUS_LOG(LOG_VERB, "Handling message: %s\n", msg->message); if(msg->message == NULL) { JANUS_LOG(LOG_ERR, "No message??\n"); error_code = JANUS_STREAMING_ERROR_NO_MESSAGE; sprintf(error_cause, "%s", "No message??"); goto error; } json_error_t error; json_t *root = json_loads(msg->message, 0, &error); if(!root) { JANUS_LOG(LOG_ERR, "JSON error: on line %d: %s\n", error.line, error.text); error_code = JANUS_STREAMING_ERROR_INVALID_JSON; sprintf(error_cause, "JSON error: on line %d: %s", error.line, error.text); goto error; } if(!json_is_object(root)) { JANUS_LOG(LOG_ERR, "JSON error: not an object\n"); error_code = JANUS_STREAMING_ERROR_INVALID_JSON; sprintf(error_cause, "JSON error: not an object"); goto error; } json_t *request = json_object_get(root, "request"); if(!request) { JANUS_LOG(LOG_ERR, "Missing element (request)\n"); error_code = JANUS_STREAMING_ERROR_MISSING_ELEMENT; sprintf(error_cause, "Missing element (request)"); goto error; } if(!json_is_string(request)) { JANUS_LOG(LOG_ERR, "Invalid element (request should be a string)\n"); error_code = JANUS_STREAMING_ERROR_INVALID_ELEMENT; sprintf(error_cause, "Invalid element (request should be a string)"); goto error; } const char *request_text = json_string_value(request); json_t *result = NULL; char *sdp_type = NULL, *sdp = NULL; if(!strcasecmp(request_text, "list")) { result = json_object(); json_t *list = json_array(); JANUS_LOG(LOG_VERB, "Request for the list of mountpoints\n"); /* Return a list of all available mountpoints */ GList *mountpoints_list = g_hash_table_get_values(mountpoints); GList *m = mountpoints_list; while(m) { janus_streaming_mountpoint *mp = (janus_streaming_mountpoint *)m->data; json_t *ml = json_object(); json_object_set_new(ml, "id", json_integer(mp->id)); json_object_set_new(ml, "description", json_string(mp->description)); json_object_set_new(ml, "type", json_string(mp->streaming_type == janus_streaming_type_live ? "live" : "on demand")); json_array_append_new(list, ml); m = m->next; } json_object_set_new(result, "list", list); g_list_free(mountpoints_list); } else if(!strcasecmp(request_text, "watch")) { json_t *id = json_object_get(root, "id"); if(id && !json_is_integer(id)) { JANUS_LOG(LOG_ERR, "Invalid element (id should be an integer)\n"); error_code = JANUS_STREAMING_ERROR_INVALID_ELEMENT; sprintf(error_cause, "Invalid element (id should be an integer)"); goto error; } gint64 id_value = json_integer_value(id); janus_streaming_mountpoint *mp = g_hash_table_lookup(mountpoints, GINT_TO_POINTER(id_value)); if(mp == NULL) { JANUS_LOG(LOG_VERB, "No such mountpoint/stream %"SCNu64"\n", id_value); error_code = JANUS_STREAMING_ERROR_NO_SUCH_MOUNTPOINT; sprintf(error_cause, "No such mountpoint/stream %"SCNu64"", id_value); goto error; } JANUS_LOG(LOG_VERB, "Request to watch mountpoint/stream %"SCNu64"\n", id_value); session->stopping = FALSE; session->mountpoint = mp; if(mp->streaming_type == janus_streaming_type_on_demand) { g_thread_new(session->mountpoint->name, &janus_streaming_ondemand_thread, session); } /* TODO Check if user is already watching a stream, if the video is active, etc. */ mp->listeners = g_list_append(mp->listeners, session); sdp_type = "offer"; /* We're always going to do the offer ourselves, never answer */ char sdptemp[1024]; memset(sdptemp, 0, 1024); gchar buffer[100]; memset(buffer, 0, 100); gint64 sessid = janus_get_monotonic_time(); gint64 version = sessid; /* FIXME This needs to be increased when it changes, so time should be ok */ g_sprintf(buffer, "v=0\r\no=%s %"SCNu64" %"SCNu64" IN IP4 127.0.0.1\r\n", "-", sessid, version); g_strlcat(sdptemp, buffer, 1024); g_strlcat(sdptemp, "s=Streaming Test\r\nt=0 0\r\n", 1024); if(mp->codecs.audio_pt >= 0) { /* Add audio line */ g_sprintf(buffer, "m=audio 1 RTP/SAVPF %d\r\n" "c=IN IP4 1.1.1.1\r\n", mp->codecs.audio_pt); g_strlcat(sdptemp, buffer, 1024); if(mp->codecs.audio_rtpmap) { g_sprintf(buffer, "a=rtpmap:%d %s\r\n", mp->codecs.audio_pt, mp->codecs.audio_rtpmap); g_strlcat(sdptemp, buffer, 1024); } g_strlcat(sdptemp, "a=sendonly\r\n", 1024); } if(mp->codecs.video_pt >= 0) { /* Add video line */ g_sprintf(buffer, "m=video 1 RTP/SAVPF %d\r\n" "c=IN IP4 1.1.1.1\r\n", mp->codecs.video_pt); g_strlcat(sdptemp, buffer, 1024); if(mp->codecs.video_rtpmap) { g_sprintf(buffer, "a=rtpmap:%d %s\r\n", mp->codecs.video_pt, mp->codecs.video_rtpmap); g_strlcat(sdptemp, buffer, 1024); } g_strlcat(sdptemp, "a=sendonly\r\n", 1024); } sdp = g_strdup(sdptemp); JANUS_LOG(LOG_VERB, "Going to offer this SDP:\n%s\n", sdp); result = json_object(); json_object_set_new(result, "status", json_string("preparing")); } else if(!strcasecmp(request_text, "start")) { JANUS_LOG(LOG_VERB, "Starting the streaming\n"); result = json_object(); /* We wait for the setup_media event to start: on the other hand, it may have already arrived */ json_object_set_new(result, "status", json_string(session->started ? "started" : "starting")); } else if(!strcasecmp(request_text, "pause")) { JANUS_LOG(LOG_VERB, "Pausing the streaming\n"); session->started = FALSE; result = json_object(); json_object_set_new(result, "status", json_string("pausing")); } else if(!strcasecmp(request_text, "stop")) { JANUS_LOG(LOG_VERB, "Stopping the streaming\n"); session->stopping = TRUE; session->started = FALSE; result = json_object(); json_object_set_new(result, "status", json_string("stopping")); if(session->mountpoint) { JANUS_LOG(LOG_VERB, " -- Removing the session from the mountpoint listeners\n"); if(g_list_find(session->mountpoint->listeners, session) != NULL) { JANUS_LOG(LOG_VERB, " -- -- Found!\n"); } session->mountpoint->listeners = g_list_remove_all(session->mountpoint->listeners, session); } session->mountpoint = NULL; } else { JANUS_LOG(LOG_VERB, "Unknown request '%s'\n", request_text); error_code = JANUS_STREAMING_ERROR_INVALID_REQUEST; sprintf(error_cause, "Unknown request '%s'", request_text); goto error; } /* Any SDP to handle? */ if(msg->sdp) { JANUS_LOG(LOG_VERB, "This is involving a negotiation (%s) as well (but we really don't care):\n%s\n", msg->sdp_type, msg->sdp); } json_decref(root); /* Prepare JSON event */ json_t *event = json_object(); json_object_set_new(event, "streaming", json_string("event")); if(result != NULL) json_object_set(event, "result", result); char *event_text = json_dumps(event, JSON_INDENT(3)); json_decref(event); if(result != NULL) json_decref(result); JANUS_LOG(LOG_VERB, "Pushing event: %s\n", event_text); int ret = gateway->push_event(msg->handle, &janus_streaming_plugin, msg->transaction, event_text, sdp_type, sdp); JANUS_LOG(LOG_VERB, " >> %d (%s)\n", ret, janus_get_api_error(ret)); g_free(event_text); if(sdp) g_free(sdp); janus_streaming_message_free(msg); continue; error: { if(root != NULL) json_decref(root); /* Prepare JSON error event */ json_t *event = json_object(); json_object_set_new(event, "streaming", json_string("event")); json_object_set_new(event, "error_code", json_integer(error_code)); json_object_set_new(event, "error", json_string(error_cause)); char *event_text = json_dumps(event, JSON_INDENT(3)); json_decref(event); JANUS_LOG(LOG_VERB, "Pushing event: %s\n", event_text); int ret = gateway->push_event(msg->handle, &janus_streaming_plugin, msg->transaction, event_text, NULL, NULL); JANUS_LOG(LOG_VERB, " >> %d (%s)\n", ret, janus_get_api_error(ret)); g_free(event_text); janus_streaming_message_free(msg); } } g_free(error_cause); JANUS_LOG(LOG_VERB, "Leaving thread\n"); return NULL; }
extern GList* stats_tree_get_cfg_list(void) { return g_hash_table_get_values(registry); }
void a_gpx_write_file ( VikTrwLayer *vtl, FILE *f, GpxWritingOptions *options ) { GpxWritingContext context = { options, f }; gpx_write_header ( f ); gchar *tmp; const gchar *name = vik_layer_get_name(VIK_LAYER(vtl)); if ( name ) { tmp = entitize ( name ); fprintf ( f, " <name>%s</name>\n", tmp ); g_free ( tmp ); } VikTRWMetadata *md = vik_trw_layer_get_metadata (vtl); if ( md ) { if ( md->author ) { tmp = entitize ( md->author ); fprintf ( f, " <author>%s</author>\n", tmp ); g_free ( tmp ); } if ( md->description ) { tmp = entitize ( md->description ); fprintf ( f, " <desc>%s</desc>\n", tmp ); g_free ( tmp ); } if ( md->timestamp ) { tmp = entitize ( md->timestamp ); fprintf ( f, " <time>%s</time>\n", tmp ); g_free ( tmp ); } if ( md->keywords ) { tmp = entitize ( md->keywords ); fprintf ( f, " <keywords>%s</keywords>\n", tmp ); g_free ( tmp ); } } if ( vik_trw_layer_get_waypoints_visibility(vtl) || (options && options->hidden) ) { // gather waypoints in a list, then sort GList *gl = g_hash_table_get_values ( vik_trw_layer_get_waypoints ( vtl ) ); gl = g_list_sort ( gl, gpx_waypoint_compare ); for (GList *iter = g_list_first (gl); iter != NULL; iter = g_list_next (iter)) { gpx_write_waypoint ( (VikWaypoint*)iter->data, &context ); } g_list_free ( gl ); } GList *gl = NULL; if ( vik_trw_layer_get_tracks_visibility(vtl) || (options && options->hidden) ) { //gl = g_hash_table_get_values ( vik_trw_layer_get_tracks ( vtl ) ); // Forming the list manually seems to produce one that is more likely to be nearer to the creation order gpointer key, value; GHashTableIter ght_iter; g_hash_table_iter_init ( &ght_iter, vik_trw_layer_get_tracks ( vtl ) ); while ( g_hash_table_iter_next (&ght_iter, &key, &value) ) { gl = g_list_prepend ( gl ,value ); } gl = g_list_reverse ( gl ); // Sort method determined by preference if ( a_vik_get_gpx_export_trk_sort() == VIK_GPX_EXPORT_TRK_SORT_TIME ) gl = g_list_sort ( gl, vik_track_compare_timestamp ); else if ( a_vik_get_gpx_export_trk_sort() == VIK_GPX_EXPORT_TRK_SORT_ALPHA ) gl = g_list_sort ( gl, gpx_track_compare_name ); } GList *glrte = NULL; // Routes sorted by name if ( vik_trw_layer_get_tracks_visibility(vtl) || (options && options->hidden) ) { glrte = g_hash_table_get_values ( vik_trw_layer_get_routes ( vtl ) ); glrte = g_list_sort ( glrte, gpx_track_compare_name ); } // g_list_concat doesn't copy memory properly // so process each list separately GpxWritingContext context_tmp = context; GpxWritingOptions opt_tmp = { FALSE, FALSE, FALSE, FALSE }; // Force trackpoints on tracks if ( !context.options ) context_tmp.options = &opt_tmp; context_tmp.options->is_route = FALSE; // Loop around each list and write each one for (GList *iter = g_list_first (gl); iter != NULL; iter = g_list_next (iter)) { gpx_write_track ( (VikTrack*)iter->data, &context_tmp ); } // Routes (to get routepoints) context_tmp.options->is_route = TRUE; for (GList *iter = g_list_first (glrte); iter != NULL; iter = g_list_next (iter)) { gpx_write_track ( (VikTrack*)iter->data, &context_tmp ); } g_list_free ( gl ); g_list_free ( glrte ); gpx_write_footer ( f ); }
/** * as_validator_get_issues: * @validator: An instance of #AsValidator. * * Get a list of found metadata format issues. * * Returns: (element-type AsValidatorIssue) (transfer container): a list of #AsValidatorIssue instances, free with g_list_free() */ GList* as_validator_get_issues (AsValidator *validator) { AsValidatorPrivate *priv = GET_PRIVATE (validator); return g_hash_table_get_values (priv->issues); }
static void _zeitgeist_log_find_received (GObject *source_object, GAsyncResult *res, gpointer user_data) { ZeitgeistLog *log = ZEITGEIST_LOG (source_object); PengeEverythingPane *pane = user_data; PengeEverythingPanePrivate *priv; GList *sw_items, *recent_file_items, *l; ZeitgeistResultSet *set = NULL; GList *old_actors = NULL; ClutterActor *actor; gboolean show_welcome_tile = TRUE; gint recent_files_count, sw_items_count; GError *error = NULL; g_return_if_fail (PENGE_IS_EVERYTHING_PANE (user_data)); priv = GET_PRIVATE (pane); set = zeitgeist_log_find_events_finish (log, res, &error); if (error != NULL) { g_warning (G_STRLOC ": Error obtaining recent files: %s", error->message); g_clear_error (&error); } /* It actually moves the interesting events into a list */ recent_file_items = _filter_out_unshowable_recent_items (pane, set); recent_file_items = g_list_sort (recent_file_items, (GCompareFunc)_recent_files_sort_func); /* Get Sw items */ sw_items = g_hash_table_get_values (priv->uuid_to_sw_items); sw_items = g_list_sort (sw_items, (GCompareFunc)_sw_item_sort_compare_func); recent_files_count = priv->block_count * priv->ratio; if (recent_files_count > g_list_length (recent_file_items)) recent_files_count = g_list_length (recent_file_items); sw_items_count = priv->block_count - recent_files_count; old_actors = g_hash_table_get_values (priv->pointer_to_actor); if (sw_items != NULL || recent_file_items != NULL) { if (priv->welcome_tile) { clutter_container_remove_actor (CLUTTER_CONTAINER (pane), priv->welcome_tile); priv->welcome_tile = NULL; } } while ((sw_items_count && sw_items) || (recent_files_count && recent_file_items)) { SwItem *sw_item = NULL; ZeitgeistEvent *recent_file_event = NULL; /* If no sw items -> force compare to favour recent file */ if (sw_items_count && sw_items) sw_item = (SwItem *)sw_items->data; else sw_item = NULL; /* If no recent files -> force compare to favour sw stuff */ if (recent_files_count && recent_file_items) recent_file_event = recent_file_items->data; else recent_file_event = NULL; if (_compare_item_and_event (sw_item, recent_file_event) < 1) { /* Sw item is newer */ actor = g_hash_table_lookup (priv->pointer_to_actor, sw_item); if (!actor) { actor = _add_from_sw_item (pane, sw_item); g_hash_table_insert (priv->pointer_to_actor, sw_item, actor); /* Needed to remove from hash when we kill the actor */ g_object_set_data (G_OBJECT (actor), "data-pointer", sw_item); } sw_items_count -= _sw_item_weight (sw_item); clutter_container_child_set (CLUTTER_CONTAINER (pane), actor, "col-span", _sw_item_weight (sw_item), NULL); sw_items = g_list_remove (sw_items, sw_item); show_welcome_tile = FALSE; } else { /* Recent file item is newer */ actor = g_hash_table_lookup (priv->pointer_to_actor, recent_file_event); if (!actor) { const gchar *uri = NULL; gchar *thumbnail_path = NULL; ZeitgeistSubject *subj; /* FIXME we assume there is only one subject */ subj = zeitgeist_event_get_subject (recent_file_event, 0); uri = zeitgeist_subject_get_uri (subj); thumbnail_path = mpl_utils_get_thumbnail_path (uri); actor = _add_from_recent_file_event (pane, recent_file_event, thumbnail_path); g_free (thumbnail_path); g_hash_table_insert (priv->pointer_to_actor, recent_file_event, actor); /* Needed to remove from hash when we kill the actor */ g_object_set_data (G_OBJECT (actor), "data-pointer", recent_file_event); show_welcome_tile = FALSE; } recent_files_count--; g_object_unref (recent_file_event); recent_file_items = g_list_remove (recent_file_items, recent_file_event); } clutter_container_lower_child (CLUTTER_CONTAINER (pane), actor, NULL); old_actors = g_list_remove (old_actors, actor); } for (l = old_actors; l; l = l->next) { gpointer p; p = g_object_get_data (G_OBJECT (l->data), "data-pointer"); if (p) { clutter_container_remove_actor (CLUTTER_CONTAINER (pane), CLUTTER_ACTOR (l->data)); g_hash_table_remove (priv->pointer_to_actor, p); } } g_list_free (old_actors); if (show_welcome_tile && !priv->welcome_tile) { priv->welcome_tile = penge_welcome_tile_new (); clutter_container_add_actor (CLUTTER_CONTAINER (pane), priv->welcome_tile); clutter_container_child_set (CLUTTER_CONTAINER (pane), priv->welcome_tile, "col-span", 3, NULL); } g_list_free (sw_items); for (l = recent_file_items; l; l = l->next) { ZeitgeistEvent *recent_file_event = l->data; g_object_unref (recent_file_event); } g_list_free (recent_file_items); }
GList *cairo_dock_get_current_applis_list (void) { return g_hash_table_get_values (s_hAppliIconsTable); }