示例#1
0
int main(int argc, char **argv)
{
    daemonize_close_stdin();

    parse_cmdline(argc, argv);

    if (!file_read_config())
        g_error("cannot read configuration file\n");

    log_init(file_config.log, file_config.verbose);

    daemonize_init(file_config.daemon_user, file_config.pidfile);

    if (!file_config.no_daemon)
        daemonize_detach();

    daemonize_write_pidfile();
    daemonize_set_user();

#ifndef NDEBUG
    if (!file_config.no_daemon)
#endif
        daemonize_close_stdout_stderr();

    main_loop = g_main_loop_new(NULL, FALSE);

    lmc_connect(file_config.host, file_config.port);
    http_client_init();
    as_init(file_config.scrobblers);

    setup_signals();

    timer = g_timer_new();

    /* set up timeouts */

    save_source_id = g_timeout_add_seconds(file_config.journal_interval,
                                           timer_save_journal, NULL);

    /* run the main loop */

    g_main_loop_run(main_loop);

    /* cleanup */

    g_message("shutting down\n");

    g_source_remove(save_source_id);
    g_main_loop_unref(main_loop);

    g_timer_destroy(timer);

    as_save_cache();
    as_cleanup();
    http_client_finish();
    lmc_disconnect();
    file_cleanup();
    log_deinit();

    daemonize_finish();

    return 0;
}
示例#2
0
static void
do_action (GtkBuilder *builder, const gchar *action, GString *string)
{
  gchar **parts;
  gint len;
  gint i;

  parts = g_strsplit (action, " ", 0);
  len = g_strv_length (parts);
  if (len > 0)
    {
      if (strcmp (parts[0], "record") == 0)
        {
          for (i = 1; i < len; i++)
            {
              GObject *o, *a;

              o = gtk_builder_get_object (builder, parts[i]);
              if (ATK_IS_OBJECT (o))
                a = o;
              else if (GTK_IS_WIDGET (o))
                a = G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (o)));
              else
                g_assert_not_reached (); 
              g_signal_connect (a, "state-change", G_CALLBACK (record_state_change), string);
            }
        }
      else if (strcmp (parts[0], "states") == 0)
        {
          g_strfreev (states);
          states = g_strdupv (parts);
        }
      else if (strcmp (parts[0], "destroy") == 0)
        {
          for (i = 1; i < len; i++)
            {
              GObject *o;

              o = gtk_builder_get_object (builder, parts[i]);
              gtk_widget_destroy (GTK_WIDGET (o));
            }
        }
      else if (strcmp (parts[0], "show") == 0)
        {
          GObject *o;

          o = gtk_builder_get_object (builder, parts[1]);
          gtk_widget_show (GTK_WIDGET (o));
        }
      else if (strcmp (parts[0], "focus") == 0)
        {
          GObject *o;

          o = gtk_builder_get_object (builder, parts[1]);
          gtk_widget_grab_focus (GTK_WIDGET (o));
        }
      else if (strcmp (parts[0], "wait") == 0)
        {
          GMainLoop *loop;
          gulong id;

          loop = g_main_loop_new (NULL, FALSE);
          id = g_timeout_add (1000, stop, loop);
          g_main_loop_run (loop);
          g_source_remove (id);
          g_main_loop_unref (loop);
        }
    }
  g_free (parts);
}
示例#3
0
static gint
check_child (gpointer data)
{
	ExecuteData   *exec_data = data;
	FrProcess     *process = exec_data->process;
	FrCommandInfo *info;
	pid_t          pid;
	int            status;
	gboolean       continue_process;

	info = g_ptr_array_index (process->priv->comm, process->priv->current_command);

	/* Remove check. */

	g_source_remove (process->priv->check_timeout);
	process->priv->check_timeout = 0;

	if (fr_channel_data_read (&process->out) == G_IO_STATUS_ERROR) {
		exec_data->error = fr_error_new (FR_ERROR_IO_CHANNEL, 0, process->out.error);
	}
	else if (fr_channel_data_read (&process->err) == G_IO_STATUS_ERROR) {
		exec_data->error = fr_error_new (FR_ERROR_IO_CHANNEL, 0, process->err.error);
	}
	else {
		pid = waitpid (process->priv->command_pid, &status, WNOHANG);
		if (pid != process->priv->command_pid) {
			/* Add check again. */
			process->priv->check_timeout = g_timeout_add (REFRESH_RATE,
							              check_child,
							              exec_data);
			return FALSE;
		}
	}

	if (info->ignore_error && (exec_data->error != NULL)) {
#ifdef DEBUG
			{
				GList *scan;

				g_print ("** ERROR **\n");
				g_print ("%s\n", exec_data->error->gerror->message);
				for (scan = process->err.raw; scan; scan = scan->next)
					g_print ("%s\n", (char *)scan->data);
			}
#endif
		fr_clear_error (&exec_data->error);
		debug (DEBUG_INFO, "[error ignored]\n");
	}
	else if (exec_data->error == NULL) {
		if (WIFEXITED (status)) {
			if (WEXITSTATUS (status) == 255) {
				exec_data->error = fr_error_new (FR_ERROR_COMMAND_NOT_FOUND, 0, NULL);
			}
			else if (WEXITSTATUS (status) != 0) {
				exec_data->error = fr_error_new (FR_ERROR_COMMAND_ERROR, WEXITSTATUS (status), NULL);
			}
		}
		else {
			exec_data->error = fr_error_new (FR_ERROR_EXITED_ABNORMALLY, 255, NULL);
		}
	}

	process->priv->command_pid = 0;

	if (exec_data->error == NULL) {
		if (fr_channel_data_flush (&process->out) == G_IO_STATUS_ERROR)
			exec_data->error = fr_error_new (FR_ERROR_IO_CHANNEL, 0, process->out.error);
		else if (fr_channel_data_flush (&process->err) == G_IO_STATUS_ERROR)
			exec_data->error = fr_error_new (FR_ERROR_IO_CHANNEL, 0, process->err.error);
	}

	if (info->end_func != NULL)
		(*info->end_func) (info->end_data);

	/**/

	if ((exec_data->error != NULL)
	    && (exec_data->error->type == FR_ERROR_IO_CHANNEL)
	    && g_error_matches (exec_data->error->gerror, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE))
	{
		if (process->priv->current_charset < n_charsets - 1) {
			/* try with another charset */
			process->priv->current_charset++;
			_fr_process_restart (exec_data);
			return FALSE;
		}
		fr_error_free (exec_data->error);
		exec_data->error = fr_error_new (FR_ERROR_BAD_CHARSET, 0, exec_data->error->gerror);
	}

	/* Check whether to continue or stop the process */

	continue_process = TRUE;
	if (info->continue_func != NULL)
		continue_process = (*info->continue_func) (&exec_data->error, info->continue_data);

	/* Execute the next command. */
	if (continue_process) {
		if (exec_data->error != NULL) {
			allow_sticky_processes_only (exec_data);
#ifdef DEBUG
			{
				GList *scan;

				g_print ("** ERROR **\n");
				for (scan = process->err.raw; scan; scan = scan->next)
					g_print ("%s\n", (char *)scan->data);
			}
#endif
		}

		if (process->priv->sticky_only) {
			do {
				process->priv->current_command++;
			}
			while ((process->priv->current_command <= process->priv->n_comm)
				&& ! command_is_sticky (process, process->priv->current_command));
		}
		else
			process->priv->current_command++;

		if (process->priv->current_command <= process->priv->n_comm) {
			execute_current_command (exec_data);
			return FALSE;
		}
	}

	/* Done */

	process->priv->current_command = -1;
	process->priv->use_standard_locale = FALSE;

	if (process->out.raw != NULL)
		process->out.raw = g_list_reverse (process->out.raw);
	if (process->err.raw != NULL)
		process->err.raw = g_list_reverse (process->err.raw);

	process->priv->running = FALSE;
	process->priv->stopping = FALSE;

	if (process->priv->sticky_only) {
		/* Restore the first error. */

		fr_error_free (exec_data->error);
		exec_data->error = fr_error_copy (exec_data->first_error);

		/* Restore the first error output as well. */

		_g_string_list_free (process->out.raw);
		process->out.raw = exec_data->first_error_stdout;
		exec_data->first_error_stdout = NULL;

		_g_string_list_free (process->err.raw);
		process->err.raw = exec_data->first_error_stderr;
		exec_data->first_error_stderr = NULL;
	}

	_fr_process_execute_complete_in_idle (exec_data);

	return FALSE;
}
示例#4
0
static void schedule_video_controls_disapearance(GtkWidget *w){
	gint timeout=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"timeout"));
	if (timeout != 0) g_source_remove(timeout);
	timeout=g_timeout_add(3000,(GSourceFunc)do_gtk_widget_destroy,w);
	g_object_set_data(G_OBJECT(w),"timeout",GINT_TO_POINTER(timeout));
}
示例#5
0
void queue_save_bookmarks(FmBookmarks* bookmarks)
{
    if(idle_handler)
        g_source_remove(idle_handler);
    idle_handler = g_idle_add((GSourceFunc)save_bookmarks, bookmarks);
}
示例#6
0
int main(int argc,char **argv)
{
	GtkWidget *win;
	GtkWidget *vbox;
	GtkWidget *hbox;
	GtkWidget *ok;
	GtkWidget *quit;
	GtkWidget *menu_bar;
	GtkWidget *menu;
	GtkWidget *label;
	TIME data;
	guint loop_t;

	gtk_init(&argc,&argv);

	win=gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_position(GTK_WINDOW(win),GTK_WIN_POS_CENTER);
	gtk_window_set_title(GTK_WINDOW(win),"TimeSetter");
	g_signal_connect(G_OBJECT(win),"delete_event",G_CALLBACK(really_quit),NULL);

	vbox=gtk_vbox_new(FALSE,0);
	gtk_container_add(GTK_CONTAINER(win),vbox);
	hbox=gtk_hbox_new(FALSE,0);

	gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0);
	label=gtk_label_new("当前时间为:");
	gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,5);
	label=gtk_label_new("00:00:00");
	gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,5);
	loop_t=g_timeout_add(1000,(GSourceFunc)display_time,label);

	gtk_box_pack_start(GTK_BOX(vbox),gtk_hseparator_new(),FALSE,FALSE,5);
	char *text[]={"年: ","月: ","日: ","时: ","分: ","秒: "};
	int i;
	for(i=0;i<6;++i)
	{
		hbox=gtk_hbox_new(FALSE,0);
		label=gtk_label_new(text[i]);
		data.data[i]=gtk_entry_new();
		gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,5);
		gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0);
		gtk_box_pack_start(GTK_BOX(hbox),data.data[i],FALSE,FALSE,0);
	}

	gtk_box_pack_start(GTK_BOX(vbox),gtk_hseparator_new(),FALSE,FALSE,5);

	ok=gtk_button_new_with_label("OK");
	quit=gtk_button_new_with_label("Quit");
	hbox=gtk_hbox_new(FALSE,0);
	gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,5);
	gtk_box_pack_start(GTK_BOX(hbox),ok,FALSE,FALSE,5);
	gtk_box_pack_end(GTK_BOX(hbox),quit,FALSE,FALSE,5);
	g_signal_connect(G_OBJECT(ok),"clicked",G_CALLBACK(set_time),&data);
	g_signal_connect(G_OBJECT(quit),"clicked",G_CALLBACK(really_quit),NULL);

	gtk_widget_show_all(win);
	gtk_main();
	g_source_remove(loop_t);
	return 0;

}
static gboolean
eventloop_input_remove(guint handle)
{
	return g_source_remove(handle);
}
示例#8
0
gboolean
admin_msg_callback(IPC_Channel * server, void *private_data)
{
    int rc = 0;
    int lpc = 0;
    xmlNode *xml = NULL;
    IPC_Message *msg = NULL;
    gboolean hack_return_good = TRUE;
    static int received_responses = 0;
    const char *result = NULL;

    g_source_remove(message_timer_id);

    while (server->ch_status != IPC_DISCONNECT && server->ops->is_message_pending(server) == TRUE) {
        rc = server->ops->recv(server, &msg);
        if (rc != IPC_OK) {
            crm_perror(LOG_ERR, "Receive failure (%d)", rc);
            return !hack_return_good;
        }

        if (msg == NULL) {
            crm_debug_4("No message this time");
            continue;
        }

        lpc++;
        received_responses++;

        xml = convert_ipc_message(msg, __FUNCTION__);
        msg->msg_done(msg);
        crm_log_xml(LOG_MSG, "ipc", xml);

        if (xml == NULL) {
            crm_info("XML in IPC message was not valid... " "discarding.");
            goto cleanup;

        } else if (validate_crm_message(xml, crm_system_name, admin_uuid,
                                        XML_ATTR_RESPONSE) == FALSE) {
            crm_debug_2("Message was not a CRM response. Discarding.");
            goto cleanup;
        }

        result = crm_element_value(xml, XML_ATTR_RESULT);
        if (result == NULL || strcasecmp(result, "ok") == 0) {
            result = "pass";
        } else {
            result = "fail";
        }

        if (DO_HEALTH) {
            xmlNode *data = get_message_xml(xml, F_CRM_DATA);
            const char *state = crm_element_value(data, "crmd_state");

            printf("Status of %s@%s: %s (%s)\n",
                   crm_element_value(data, XML_PING_ATTR_SYSFROM),
                   crm_element_value(xml, F_CRM_HOST_FROM),
                   state, crm_element_value(data, XML_PING_ATTR_STATUS));

            if (BE_SILENT && state != NULL) {
                fprintf(stderr, "%s\n", state);
            }

        } else if (DO_WHOIS_DC) {
            const char *dc = crm_element_value(xml, F_CRM_HOST_FROM);

            printf("Designated Controller is: %s\n", dc);
            if (BE_SILENT && dc != NULL) {
                fprintf(stderr, "%s\n", dc);
            }
        }

  cleanup:
        free_xml(xml);
        xml = NULL;
    }

    if (server->ch_status == IPC_DISCONNECT) {
        crm_debug_2("admin_msg_callback: received HUP");
        return !hack_return_good;
    }

    if (received_responses >= expected_responses) {
        crm_debug_2("Received expected number (%d) of messages from Heartbeat."
                    "  Exiting normally.", expected_responses);
        exit(0);
    }

    message_timer_id = g_timeout_add(message_timeout_ms, admin_message_timeout, NULL);

    return hack_return_good;
}
示例#9
0
void RosReconfigure_callback(Config &config, uint32_t level)
{
    int             changedAcquire;
    int             changedAcquisitionFrameRate;
    int             changedExposureAuto;
    int             changedGainAuto;
    int             changedExposureTimeAbs;
    int             changedGain;
    int             changedAcquisitionMode;
    int             changedTriggerMode;
    int             changedTriggerSource;
    int             changedSoftwarerate;
    int             changedFrameid;
    int             changedFocusPos;
    int             changedMtu;
    
    
    std::string tf_prefix = tf::getPrefixParam(*global.phNode);
    ROS_DEBUG_STREAM("tf_prefix: " << tf_prefix);
    
    if (config.frame_id == "")
        config.frame_id = "camera";

    
    // Find what the user changed.
    changedAcquire    			= (global.config.Acquire != config.Acquire);
    changedAcquisitionFrameRate = (global.config.AcquisitionFrameRate != config.AcquisitionFrameRate);
    changedExposureAuto 		= (global.config.ExposureAuto != config.ExposureAuto);
    changedExposureTimeAbs  	= (global.config.ExposureTimeAbs != config.ExposureTimeAbs);
    changedGainAuto     		= (global.config.GainAuto != config.GainAuto);
    changedGain         		= (global.config.Gain != config.Gain);
    changedAcquisitionMode 		= (global.config.AcquisitionMode != config.AcquisitionMode);
    changedTriggerMode  		= (global.config.TriggerMode != config.TriggerMode);
    changedTriggerSource		= (global.config.TriggerSource != config.TriggerSource);
    changedSoftwarerate  		= (global.config.softwaretriggerrate != config.softwaretriggerrate);
    changedFrameid      		= (global.config.frame_id != config.frame_id);
    changedFocusPos     		= (global.config.FocusPos != config.FocusPos);
    changedMtu          		= (global.config.mtu != config.mtu);


    // Limit params to legal values.
    config.AcquisitionFrameRate = CLIP(config.AcquisitionFrameRate, global.configMin.AcquisitionFrameRate, 	global.configMax.AcquisitionFrameRate);
    config.ExposureTimeAbs   	= CLIP(config.ExposureTimeAbs,  	global.configMin.ExposureTimeAbs,  		global.configMax.ExposureTimeAbs);
    config.Gain          		= CLIP(config.Gain,         		global.configMin.Gain,         			global.configMax.Gain);
    config.FocusPos       		= CLIP(config.FocusPos,      		global.configMin.FocusPos,      		global.configMax.FocusPos);
    config.frame_id   			= tf::resolve(tf_prefix, config.frame_id);


    // Adjust other controls dependent on what the user changed.
    if (changedExposureTimeAbs || changedGainAuto || ((changedAcquisitionFrameRate || changedGain || changedFrameid
					|| changedAcquisitionMode || changedTriggerSource || changedSoftwarerate) && config.ExposureAuto=="Once"))
    	config.ExposureAuto = "Off";

    if (changedGain || changedExposureAuto || ((changedAcquisitionFrameRate || changedExposureTimeAbs || changedFrameid
					|| changedAcquisitionMode || changedTriggerSource || changedSoftwarerate) && config.GainAuto=="Once"))
    	config.GainAuto = "Off";

    if (changedAcquisitionFrameRate)
    	config.TriggerMode = "Off";


    // Find what changed for any reason.
    changedAcquire    			= (global.config.Acquire != config.Acquire);
    changedAcquisitionFrameRate = (global.config.AcquisitionFrameRate != config.AcquisitionFrameRate);
    changedExposureAuto 		= (global.config.ExposureAuto != config.ExposureAuto);
    changedExposureTimeAbs     	= (global.config.ExposureTimeAbs != config.ExposureTimeAbs);
    changedGainAuto     		= (global.config.GainAuto != config.GainAuto);
    changedGain            		= (global.config.Gain != config.Gain);
    changedAcquisitionMode 		= (global.config.AcquisitionMode != config.AcquisitionMode);
    changedTriggerMode  		= (global.config.TriggerMode != config.TriggerMode);
    changedTriggerSource		= (global.config.TriggerSource != config.TriggerSource);
    changedSoftwarerate  		= (global.config.softwaretriggerrate != config.softwaretriggerrate);
    changedFrameid      		= (global.config.frame_id != config.frame_id);
    changedFocusPos     		= (global.config.FocusPos != config.FocusPos);
    changedMtu          		= (global.config.mtu != config.mtu);

    
    // Set params into the camera.
    if (changedExposureTimeAbs)
    {
    	if (global.isImplementedExposureTimeAbs)
		{
			ROS_INFO ("Set ExposureTimeAbs = %f", config.ExposureTimeAbs);
			arv_device_set_float_feature_value (global.pDevice, "ExposureTimeAbs", config.ExposureTimeAbs);
		}
    	else
    		ROS_INFO ("Camera does not support ExposureTimeAbs.");
    }

    if (changedGain)
    {
    	if (global.isImplementedGain)
		{
			ROS_INFO ("Set gain = %f", config.Gain);
			//arv_device_set_integer_feature_value (global.pDevice, "GainRaw", config.GainRaw);
			arv_camera_set_gain (global.pCamera, config.Gain);
		}
    	else
    		ROS_INFO ("Camera does not support Gain or GainRaw.");
    }

    if (changedExposureAuto)
    {
    	if (global.isImplementedExposureAuto && global.isImplementedExposureTimeAbs)
		{
			ROS_INFO ("Set ExposureAuto = %s", config.ExposureAuto.c_str());
			arv_device_set_string_feature_value (global.pDevice, "ExposureAuto", config.ExposureAuto.c_str());
			if (config.ExposureAuto=="Once")
			{
				ros::Duration(2.0).sleep();
				config.ExposureTimeAbs = arv_device_get_float_feature_value (global.pDevice, "ExposureTimeAbs");
				ROS_INFO ("Get ExposureTimeAbs = %f", config.ExposureTimeAbs);
				config.ExposureAuto = "Off";
			}
		}
    	else
    		ROS_INFO ("Camera does not support ExposureAuto.");
    }
    if (changedGainAuto)
    {
    	if (global.isImplementedGainAuto && global.isImplementedGain)
		{
			ROS_INFO ("Set GainAuto = %s", config.GainAuto.c_str());
			arv_device_set_string_feature_value (global.pDevice, "GainAuto", config.GainAuto.c_str());
			if (config.GainAuto=="Once")
			{
				ros::Duration(2.0).sleep();
				//config.GainRaw = arv_device_get_integer_feature_value (global.pDevice, "GainRaw");
				config.Gain = arv_camera_get_gain (global.pCamera);
				ROS_INFO ("Get Gain = %f", config.Gain);
				config.GainAuto = "Off";
			}
		}
    	else
    		ROS_INFO ("Camera does not support GainAuto.");
    }

    if (changedAcquisitionFrameRate)
    {
    	if (global.isImplementedAcquisitionFrameRate)
		{
			ROS_INFO ("Set %s = %f", global.keyAcquisitionFrameRate, config.AcquisitionFrameRate);
			arv_device_set_float_feature_value (global.pDevice, global.keyAcquisitionFrameRate, config.AcquisitionFrameRate);
		}
    	else
    		ROS_INFO ("Camera does not support AcquisitionFrameRate.");
    }

    if (changedTriggerMode)
    {
    	if (global.isImplementedTriggerMode)
		{
			ROS_INFO ("Set TriggerMode = %s", config.TriggerMode.c_str());
			arv_device_set_string_feature_value (global.pDevice, "TriggerMode", config.TriggerMode.c_str());
		}
    	else
    		ROS_INFO ("Camera does not support TriggerMode.");
    }

    if (changedTriggerSource)
    {
    	if (global.isImplementedTriggerSource)
		{
			ROS_INFO ("Set TriggerSource = %s", config.TriggerSource.c_str());
			arv_device_set_string_feature_value (global.pDevice, "TriggerSource", config.TriggerSource.c_str());
		}
    	else
    		ROS_INFO ("Camera does not support TriggerSource.");
    }

    if ((changedTriggerMode || changedTriggerSource || changedSoftwarerate) && config.TriggerMode=="On" && config.TriggerSource=="Software")
    {
    	if (global.isImplementedAcquisitionFrameRate)
		{
			// The software rate is limited by the camera's internal framerate.  Bump up the camera's internal framerate if necessary.
			config.AcquisitionFrameRate = global.configMax.AcquisitionFrameRate;
			ROS_INFO ("Set %s = %f", global.keyAcquisitionFrameRate, config.AcquisitionFrameRate);
			arv_device_set_float_feature_value (global.pDevice, global.keyAcquisitionFrameRate, config.AcquisitionFrameRate);
		}
    }

    if (changedTriggerSource || changedSoftwarerate)
    {
    	// Recreate the software trigger callback.
		if (global.idSoftwareTriggerTimer)
		{
			g_source_remove(global.idSoftwareTriggerTimer);
			global.idSoftwareTriggerTimer = 0;
		}
    	if (!strcmp(config.TriggerSource.c_str(),"Software"))
    	{
        	ROS_INFO ("Set softwaretriggerrate = %f", 1000.0/ceil(1000.0 / config.softwaretriggerrate));

    		// Turn on software timer callback.
    		global.idSoftwareTriggerTimer = g_timeout_add ((guint)ceil(1000.0 / config.softwaretriggerrate), SoftwareTrigger_callback, global.pCamera);
    	}
    }
    if (changedFocusPos)
    {
    	if (global.isImplementedFocusPos)
		{
			ROS_INFO ("Set FocusPos = %d", config.FocusPos);
			arv_device_set_integer_feature_value(global.pDevice, "FocusPos", config.FocusPos);
			ros::Duration(1.0).sleep();
			config.FocusPos = arv_device_get_integer_feature_value(global.pDevice, "FocusPos");
			ROS_INFO ("Get FocusPos = %d", config.FocusPos);
		}
    	else
    		ROS_INFO ("Camera does not support FocusPos.");
    }
    if (changedMtu)
    {
    	if (global.isImplementedMtu)
		{
			ROS_INFO ("Set mtu = %d", config.mtu);
			arv_device_set_integer_feature_value(global.pDevice, "GevSCPSPacketSize", config.mtu);
			ros::Duration(1.0).sleep();
			config.mtu = arv_device_get_integer_feature_value(global.pDevice, "GevSCPSPacketSize");
			ROS_INFO ("Get mtu = %d", config.mtu);
		}
    	else
    		ROS_INFO ("Camera does not support mtu (i.e. GevSCPSPacketSize).");
    }

    if (changedAcquisitionMode)
    {
    	if (global.isImplementedAcquisitionMode)
		{
			ROS_INFO ("Set AcquisitionMode = %s", config.AcquisitionMode.c_str());
			arv_device_set_string_feature_value (global.pDevice, "AcquisitionMode", config.AcquisitionMode.c_str());

			ROS_INFO("AcquisitionStop");
			arv_device_execute_command (global.pDevice, "AcquisitionStop");
			ROS_INFO("AcquisitionStart");
			arv_device_execute_command (global.pDevice, "AcquisitionStart");
		}
    	else
    		ROS_INFO ("Camera does not support AcquisitionMode.");
    }

    if (changedAcquire)
    {
    	if (config.Acquire)
    	{
    		ROS_INFO("AcquisitionStart");
			arv_device_execute_command (global.pDevice, "AcquisitionStart");
    	}
    	else
    	{
    		ROS_INFO("AcquisitionStop");
			arv_device_execute_command (global.pDevice, "AcquisitionStop");
    	}
    }



    global.config = config;

} // RosReconfigure_callback()
示例#10
0
static void server_connect_callback_readpipe(SERVER_REC *server)
{
	RESOLVED_IP_REC iprec;
        IPADDR *ip;
	const char *errormsg;
	char *servername = NULL;

	g_source_remove(server->connect_tag);
	server->connect_tag = -1;

	net_gethostbyname_return(server->connect_pipe[0], &iprec);

	g_io_channel_shutdown(server->connect_pipe[0], TRUE, NULL);
	g_io_channel_unref(server->connect_pipe[0]);
	g_io_channel_shutdown(server->connect_pipe[1], TRUE, NULL);
	g_io_channel_unref(server->connect_pipe[1]);

	server->connect_pipe[0] = NULL;
	server->connect_pipe[1] = NULL;

	/* figure out if we should use IPv4 or v6 address */
	if (iprec.error != 0) {
                /* error */
		ip = NULL;
	} else if (server->connrec->family == AF_INET) {
		/* force IPv4 connection */
		ip = iprec.ip4.family == 0 ? NULL : &iprec.ip4;
		servername = iprec.host4;
	} else if (server->connrec->family == AF_INET6) {
		/* force IPv6 connection */
		ip = iprec.ip6.family == 0 ? NULL : &iprec.ip6;
		servername = iprec.host6;
	} else {
		/* pick the one that was found, or if both do it like
		   /SET resolve_prefer_ipv6 says. */
		if (iprec.ip4.family == 0 ||
		    (iprec.ip6.family != 0 &&
		     settings_get_bool("resolve_prefer_ipv6"))) {
			ip = &iprec.ip6;
			servername = iprec.host6;
		} else {
			ip = &iprec.ip4;
			servername = iprec.host4;
		}
	}

	if (ip != NULL) {
		/* host lookup ok */
		if (servername) {
			g_free(server->connrec->address);
			server->connrec->address = g_strdup(servername);
		}
		server_real_connect(server, ip, NULL);
		errormsg = NULL;
	} else {
		if (iprec.error == 0 || net_hosterror_notfound(iprec.error)) {
			/* IP wasn't found for the host, don't try to
			   reconnect back to this server */
			server->dns_error = TRUE;
		}

		if (iprec.error == 0) {
			/* forced IPv4 or IPv6 address but it wasn't found */
			errormsg = server->connrec->family == AF_INET ?
				"IPv4 address not found for host" :
				"IPv6 address not found for host";
		} else {
			/* gethostbyname() failed */
			errormsg = iprec.errorstr != NULL ? iprec.errorstr :
				"Host lookup failed";
		}

		server->connection_lost = TRUE;
		server_connect_failed(server, errormsg);
	}

	g_free(iprec.errorstr);
	g_free(iprec.host4);
	g_free(iprec.host6);
}
示例#11
0
static void
_eventd_nd_notification_process(EventdNdNotification *self, EventdEvent *event)
{
    _eventd_nd_notification_clean(self);
    if ( event != NULL )
        self->event = eventd_event_ref(event);

    gint border, padding;
    gint progress_bar_width = 0;
    gint min_width, max_width;

    gint text_width = 0, text_max_width;
    gint image_width = 0, image_height = 0;


    switch ( self->context->shaping )
    {
    case EVENTD_ND_SHAPING_NONE:
    case EVENTD_ND_SHAPING_SHAPE:
        self->offset.x = 0;
        self->offset.y = 0;
        self->surface_size.width = 0;
        self->surface_size.height = 0;
    break;
    case EVENTD_ND_SHAPING_COMPOSITING:
    {
        gint blur, offset_x, offset_y;
        blur = eventd_nd_style_get_bubble_border_blur(self->style) * 2; /* We must reserve enough space to avoid clipping */
        offset_x = eventd_nd_style_get_bubble_border_blur_offset_x(self->style);
        offset_y = eventd_nd_style_get_bubble_border_blur_offset_y(self->style);

        self->offset.x = MAX(0, blur - offset_x);
        self->offset.y = MAX(0, blur - offset_y);
        self->surface_size.width = 2 * blur + MAX(0, ABS(offset_x) - blur);
        self->surface_size.height = 2 * blur + MAX(0, ABS(offset_y) - blur);
    }
    break;
    }
    border = eventd_nd_style_get_bubble_border(self->style);
    padding = eventd_nd_style_get_bubble_padding(self->style);
    min_width = eventd_nd_style_get_bubble_min_width(self->style);
    max_width = eventd_nd_style_get_bubble_max_width(self->style);

    switch ( eventd_nd_style_get_progress_placement(self->style) )
    {
    case EVENTD_ND_STYLE_PROGRESS_PLACEMENT_BAR_BOTTOM:
        if ( self->event != NULL )
        {
            GVariant *val;

            val = eventd_event_get_data(self->event, eventd_nd_style_get_template_progress(self->style));
            if ( val != NULL )
                progress_bar_width = eventd_nd_style_get_progress_bar_width(self->style);
        }
    break;
    case EVENTD_ND_STYLE_PROGRESS_PLACEMENT_IMAGE_BOTTOM_TOP:
    case EVENTD_ND_STYLE_PROGRESS_PLACEMENT_IMAGE_TOP_BOTTOM:
    case EVENTD_ND_STYLE_PROGRESS_PLACEMENT_IMAGE_LEFT_RIGHT:
    case EVENTD_ND_STYLE_PROGRESS_PLACEMENT_IMAGE_RIGHT_LEFT:
    case EVENTD_ND_STYLE_PROGRESS_PLACEMENT_IMAGE_CIRCULAR:
    break;
    }

    if ( max_width < 0 )
        max_width = self->context->geometry.w - 2 * ( self->queue->margin_x + border );
    max_width -= 2 * padding;
    min_width += 2 * padding;
    if ( min_width > max_width )
        min_width = max_width;

    /* proccess data and compute the bubble size */
    text_max_width = eventd_nd_style_get_text_max_width(self->style);
    if ( text_max_width < 0 )
        text_max_width = max_width;
    else
        text_max_width = MIN(text_max_width, max_width);
    self->text.text = eventd_nd_draw_text_process(self->style, self->event, text_max_width, g_queue_get_length(self->queue->wait_queue), &text_width);

    self->content_size.width = text_width;

    if ( self->content_size.width < max_width )
    {
        if ( self->event != NULL )
            eventd_nd_draw_image_and_icon_process(self->context->theme_context, self->style, self->event, max_width - self->content_size.width, self->context->geometry.s, &self->image, &self->icon, &self->text.x, &image_width, &image_height);
        self->content_size.width += image_width;
    }

    /* We are sure that min_width <= max_width */
    if ( min_width > self->content_size.width )
    {
        self->content_size.width = min_width;
        /* Let the text take the remaining space if needed (e.g. Right-to-Left) */
        text_width = self->content_size.width - image_width;
    }
    pango_layout_set_width(self->text.text, text_width * PANGO_SCALE);
    pango_layout_get_pixel_size(self->text.text, NULL, &self->text.height);

    self->content_size.height = MAX(image_height, self->text.height);

    self->bubble_size.width = self->content_size.width + 2 * padding;
    self->bubble_size.height = self->content_size.height + 2 * padding + progress_bar_width;
    self->border_size.width = self->bubble_size.width + 2 * border;
    self->border_size.height = self->bubble_size.height + 2 * border;
    self->surface_size.width += self->border_size.width;
    self->surface_size.height += self->border_size.height;

    if ( self->timeout > 0 )
    {
        g_source_remove(self->timeout);
        self->timeout = g_timeout_add_full(G_PRIORITY_DEFAULT, eventd_nd_style_get_bubble_timeout(self->style), _eventd_nd_event_timedout, self, NULL);
    }
}
示例#12
0
文件: vteapp.c 项目: ari3s/vte
static void
disconnect_watch(gpointer data)
{
	g_source_remove(GPOINTER_TO_INT(data));
}
示例#13
0
文件: gtktooltip.c 项目: Vasileus/gtk
static void
gtk_tooltip_show_tooltip (GdkDisplay *display)
{
  gint x, y;
  GdkScreen *screen;

  GdkWindow *window;
  GtkWidget *tooltip_widget;
  GtkTooltip *tooltip;
  gboolean has_tooltip;
  gboolean return_value = FALSE;

  tooltip = g_object_get_data (G_OBJECT (display),
                               "gdk-display-current-tooltip");

  if (tooltip->keyboard_mode_enabled)
    {
      x = y = -1;
      tooltip_widget = tooltip->keyboard_widget;
    }
  else
    {
      GdkDevice *device;
      gint tx, ty;

      window = tooltip->last_window;

      if (!GDK_IS_WINDOW (window))
        return;

      device = gdk_device_manager_get_client_pointer (gdk_display_get_device_manager (display));

      gdk_window_get_device_position (window, device, &x, &y, NULL);

      gdk_window_get_root_coords (window, x, y, &tx, &ty);
      tooltip->last_x = tx;
      tooltip->last_y = ty;

      tooltip_widget = _gtk_widget_find_at_coords (window, x, y, &x, &y);
    }

  if (!tooltip_widget)
    return;

  g_object_get (tooltip_widget, "has-tooltip", &has_tooltip, NULL);

  return_value = gtk_tooltip_run_requery (&tooltip_widget, tooltip, &x, &y);
  if (!return_value)
    return;

  if (!tooltip->current_window)
    {
      if (gtk_widget_get_tooltip_window (tooltip_widget))
        tooltip->current_window = gtk_widget_get_tooltip_window (tooltip_widget);
      else
        tooltip->current_window = GTK_WINDOW (GTK_TOOLTIP (tooltip)->window);
    }

  screen = gtk_widget_get_screen (tooltip_widget);

  /* FIXME: should use tooltip->current_window iso tooltip->window */
  if (screen != gtk_widget_get_screen (tooltip->window))
    {
      g_signal_handlers_disconnect_by_func (display,
                                            gtk_tooltip_display_closed,
                                            tooltip);

      gtk_window_set_screen (GTK_WINDOW (tooltip->window), screen);

      g_signal_connect (display, "closed",
                        G_CALLBACK (gtk_tooltip_display_closed), tooltip);
    }

  gtk_tooltip_position (tooltip, display, tooltip_widget);

  /* Now a tooltip is visible again on the display, make sure browse
   * mode is enabled.
   */
  tooltip->browse_mode_enabled = TRUE;
  if (tooltip->browse_mode_timeout_id)
    {
      g_source_remove (tooltip->browse_mode_timeout_id);
      tooltip->browse_mode_timeout_id = 0;
    }
}
示例#14
0
文件: main.c 项目: frankzhao/storaged
int
main (int    argc,
      char **argv)
{
  GError *error;
  GOptionContext *opt_context;
  gint ret;
  guint name_owner_id;
  guint sigint_id;

  ret = 1;
  loop = NULL;
  opt_context = NULL;
  name_owner_id = 0;
  sigint_id = 0;

  /* avoid gvfs (http://bugzilla.gnome.org/show_bug.cgi?id=526454) */
  if (!g_setenv ("GIO_USE_VFS", "local", TRUE))
    {
      g_printerr ("Error setting GIO_USE_GVFS\n");
      goto out;
    }

  opt_context = g_option_context_new ("storaged storage daemon");
  g_option_context_add_main_entries (opt_context, opt_entries, NULL);
  error = NULL;
  if (!g_option_context_parse (opt_context, &argc, &argv, &error))
    {
      g_printerr ("Error parsing options: %s\n", error->message);
      g_error_free (error);
      goto out;
    }

  /* TODO: this hammer is too big - it would be a lot better to configure the
   *       logging routines and avoid printf(3) overhead and so on
   */
  if (opt_no_debug)
    {
      gint dev_null_fd;
      dev_null_fd = open ("/dev/null", O_RDWR);
      if (dev_null_fd >= 0)
        {
          dup2 (dev_null_fd, STDIN_FILENO);
          dup2 (dev_null_fd, STDOUT_FILENO);
          dup2 (dev_null_fd, STDERR_FILENO);
          close (dev_null_fd);
        }
      else
        {
          storaged_warning ("Error opening /dev/null: %m");
        }
    }

  if (g_getenv ("PATH") == NULL)
    g_setenv ("PATH", "/usr/bin:/bin:/usr/sbin:/sbin", TRUE);

  storaged_notice ("storaged daemon version %s starting", PACKAGE_VERSION);

  loop = g_main_loop_new (NULL, FALSE);

  sigint_id = 0;
  if (!opt_no_sigint)
    {
      sigint_id = g_unix_signal_add_full (G_PRIORITY_DEFAULT,
                                          SIGINT,
                                          on_sigint,
                                          NULL,  /* user_data */
                                          NULL); /* GDestroyNotify */
    }

  name_owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
                                  "org.storaged.Storaged",
                                  G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
                                    (opt_replace ? G_BUS_NAME_OWNER_FLAGS_REPLACE : 0),
                                  on_bus_acquired,
                                  on_name_acquired,
                                  on_name_lost,
                                  NULL,
                                  NULL);


  storaged_debug ("Entering main event loop");

  g_main_loop_run (loop);

  ret = 0;

 out:
  if (sigint_id > 0)
    g_source_remove (sigint_id);
  if (the_daemon != NULL)
    g_object_unref (the_daemon);
  if (name_owner_id != 0)
    g_bus_unown_name (name_owner_id);
  if (loop != NULL)
    g_main_loop_unref (loop);
  if (opt_context != NULL)
    g_option_context_free (opt_context);

  storaged_notice ("storaged daemon version %s exiting", PACKAGE_VERSION);

  return ret;
}
static void
rejilla_burn_options_update_valid (RejillaBurnOptions *self)
{
	RejillaBurnOptionsPrivate *priv;
	RejillaSessionError valid;

	priv = REJILLA_BURN_OPTIONS_PRIVATE (self);

	valid = rejilla_session_cfg_get_error (priv->session);
	priv->is_valid = REJILLA_SESSION_IS_VALID (valid);

	rejilla_burn_options_setup_buttons (self);

	gtk_widget_set_sensitive (priv->options, priv->is_valid);
	gtk_widget_set_sensitive (priv->properties, priv->is_valid);

	if (priv->message_input) {
		gtk_widget_hide (priv->message_input);
		rejilla_notify_message_remove (priv->message_input,
					       REJILLA_NOTIFY_CONTEXT_SIZE);
	}

	rejilla_notify_message_remove (priv->message_output,
				       REJILLA_NOTIFY_CONTEXT_SIZE);

	if (valid == REJILLA_SESSION_NOT_READY) {
		if (!priv->not_ready_id && !priv->status_dialog) {
			gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
			priv->status_dialog = rejilla_status_dialog_new (REJILLA_BURN_SESSION (priv->session),  GTK_WIDGET (self));
			g_signal_connect (priv->status_dialog,
					  "response", 
					  G_CALLBACK (rejilla_burn_options_not_ready_dialog_cancel_cb),
					  self);

			g_signal_connect (priv->status_dialog,
					  "show", 
					  G_CALLBACK (rejilla_burn_options_not_ready_dialog_shown_cb),
					  self);
			g_signal_connect (priv->status_dialog,
					  "user-interaction", 
					  G_CALLBACK (rejilla_burn_options_not_ready_dialog_shown_cb),
					  self);

			priv->not_ready_id = g_timeout_add_seconds (1,
								    rejilla_burn_options_not_ready_dialog_show_cb,
								    self);
		}
	}
	else {
		gtk_widget_set_sensitive (GTK_WIDGET (self), TRUE);
		if (priv->status_dialog) {
			gtk_widget_destroy (priv->status_dialog);
			priv->status_dialog = NULL;
		}

		if (priv->not_ready_id) {
			g_source_remove (priv->not_ready_id);
			priv->not_ready_id = 0;
		}
	}

	if (valid == REJILLA_SESSION_INSUFFICIENT_SPACE) {
		goffset min_disc_size;
		goffset available_space;

		min_disc_size = rejilla_session_span_get_max_space (REJILLA_SESSION_SPAN (priv->session));

		/* One rule should be that the maximum batch size should not exceed the disc size
		 * FIXME: we could change it into a dialog telling the user what is the maximum
		 * size required. */
		available_space = rejilla_burn_session_get_available_medium_space (REJILLA_BURN_SESSION (priv->session));

		/* Here there is an alternative: we may be able to span the data
		 * across multiple media. So try that. */
		if (available_space > min_disc_size
		&&  rejilla_session_span_possible (REJILLA_SESSION_SPAN (priv->session)) == REJILLA_BURN_RETRY) {
			GtkWidget *message;

			message = rejilla_notify_message_add (priv->message_output,
							      _("Would you like to burn the selection of files across several media?"),
							      _("The data size is too large for the disc even with the overburn option."),
							      -1,
							      REJILLA_NOTIFY_CONTEXT_SIZE);

			gtk_widget_set_tooltip_text (gtk_info_bar_add_button (GTK_INFO_BAR (message),
									      _("_Burn Several Discs"),
									      GTK_RESPONSE_OK),
						    _("Burn the selection of files across several media"));

			g_signal_connect (message,
					  "response",
					  G_CALLBACK (rejilla_burn_options_message_response_span_cb),
					  self);
		}
		else
			rejilla_notify_message_add (priv->message_output,
						    _("Please choose another CD or DVD or insert a new one."),
						    _("The data size is too large for the disc even with the overburn option."),
						    -1,
						    REJILLA_NOTIFY_CONTEXT_SIZE);
	}
	else if (valid == REJILLA_SESSION_NO_OUTPUT) {
		rejilla_notify_message_add (priv->message_output,
					    _("Please insert a writable CD or DVD."),
					    NULL,
					    -1,
					    REJILLA_NOTIFY_CONTEXT_SIZE);
	}
	else if (valid == REJILLA_SESSION_NO_CD_TEXT) {
		rejilla_notify_message_add (priv->message_output,
					    _("No track information (artist, title, ...) will be written to the disc."),
					    _("This is not supported by the current active burning backend."),
					    -1,
					    REJILLA_NOTIFY_CONTEXT_SIZE);
	}
	else if (valid == REJILLA_SESSION_EMPTY) {
		RejillaTrackType *type;
		
		type = rejilla_track_type_new ();
		rejilla_burn_session_get_input_type (REJILLA_BURN_SESSION (priv->session), type);

		if (rejilla_track_type_get_has_data (type))
			rejilla_notify_message_add (priv->message_output,
						    _("Please add files."),
						    _("There are no files to write to disc"),
						    -1,
						    REJILLA_NOTIFY_CONTEXT_SIZE);
		else if (!REJILLA_STREAM_FORMAT_HAS_VIDEO (rejilla_track_type_get_stream_format (type)))
			rejilla_notify_message_add (priv->message_output,
						    _("Please add songs."),
						    _("There are no songs to write to disc"),
						    -1,
						    REJILLA_NOTIFY_CONTEXT_SIZE);
		else
			rejilla_notify_message_add (priv->message_output,
						     _("Please add videos."),
						    _("There are no videos to write to disc"),
						    -1,
						    REJILLA_NOTIFY_CONTEXT_SIZE);
		rejilla_track_type_free (type);
		gtk_window_resize (GTK_WINDOW (self), 10, 10);
		return;		      
	}
	else if (valid == REJILLA_SESSION_NO_INPUT_MEDIUM) {
		GtkWidget *message;

		if (priv->message_input) {
			gtk_widget_show (priv->message_input);
			message = rejilla_notify_message_add (priv->message_input,
							      _("Please insert a disc holding data."),
							      _("There is no inserted disc to copy."),
							      -1,
							      REJILLA_NOTIFY_CONTEXT_SIZE);
		}
	}
	else if (valid == REJILLA_SESSION_NO_INPUT_IMAGE) {
		GtkWidget *message;

		if (priv->message_input) {
			gtk_widget_show (priv->message_input);
			message = rejilla_notify_message_add (priv->message_input,
							      _("Please select a disc image."),
							      _("There is no selected disc image."),
							      -1,
							      REJILLA_NOTIFY_CONTEXT_SIZE);
		}
	}
	else if (valid == REJILLA_SESSION_UNKNOWN_IMAGE) {
		GtkWidget *message;

		if (priv->message_input) {
			gtk_widget_show (priv->message_input);
			message = rejilla_notify_message_add (priv->message_input,
							      /* Translators: this is a disc image not a picture */
							      C_("disc", "Please select another image."),
							      _("It doesn't appear to be a valid disc image or a valid cue file."),
							      -1,
							      REJILLA_NOTIFY_CONTEXT_SIZE);
		}
	}
	else if (valid == REJILLA_SESSION_DISC_PROTECTED) {
		GtkWidget *message;

		if (priv->message_input) {
			gtk_widget_show (priv->message_input);
			message = rejilla_notify_message_add (priv->message_input,
							      _("Please insert a disc that is not copy protected."),
							      _("All required applications and libraries are not installed."),
							      -1,
							      REJILLA_NOTIFY_CONTEXT_SIZE);
		}
	}
	else if (valid == REJILLA_SESSION_NOT_SUPPORTED) {
		rejilla_notify_message_add (priv->message_output,
		                            _("Please replace the disc with a supported CD or DVD."),
		                            NULL,
		                            -1,
		                            REJILLA_NOTIFY_CONTEXT_SIZE);
	}
	else if (valid == REJILLA_SESSION_OVERBURN_NECESSARY) {
		GtkWidget *message;

		message = rejilla_notify_message_add (priv->message_output,
						      _("Would you like to burn beyond the disc's reported capacity?"),
						      _("The data size is too large for the disc and you must remove files from the selection otherwise."
							"\nYou may want to use this option if you're using 90 or 100 min CD-R(W) which cannot be properly recognised and therefore need overburn option."
							"\nNOTE: This option might cause failure."),
						      -1,
						      REJILLA_NOTIFY_CONTEXT_SIZE);

		gtk_widget_set_tooltip_text (gtk_info_bar_add_button (GTK_INFO_BAR (message),
								      _("_Overburn"),
								      GTK_RESPONSE_OK),
					     _("Burn beyond the disc's reported capacity"));

		g_signal_connect (message,
				  "response",
				  G_CALLBACK (rejilla_burn_options_message_response_cb),
				  self);
	}
	else if (rejilla_burn_session_same_src_dest_drive (REJILLA_BURN_SESSION (priv->session))) {
		/* The medium is valid but it's a special case */
		rejilla_notify_message_add (priv->message_output,
					    _("The drive that holds the source disc will also be the one used to record."),
					    _("A new writable disc will be required once the currently loaded one has been copied."),
					    -1,
					    REJILLA_NOTIFY_CONTEXT_SIZE);
		gtk_widget_show_all (priv->message_output);
	}

	rejilla_burn_options_update_no_medium_warning (self);
	gtk_window_resize (GTK_WINDOW (self), 10, 10);
}
示例#16
0
int main(int argc, char** argv) 
{
    char   		*pszGuid = NULL;
    char    	 szGuid[512];
    int			 nInterfaces = 0;
    int			 nDevices = 0;
    int 		 i = 0;
	const char	*pkeyAcquisitionFrameRate[2] = {"AcquisitionFrameRate", "AcquisitionFrameRateAbs"};
    ArvGcNode	*pGcNode;
	GError		*error=NULL;

    global.bCancel = FALSE;
    global.config = global.config.__getDefault__();
    global.idSoftwareTriggerTimer = 0;

    ros::init(argc, argv, "camera");
    global.phNode = new ros::NodeHandle();


    // Service callback for firing nuc's. 
	// Needed since we cannot open another connection to cameras while streaming.
	ros::NodeHandle nh;
	ros::ServiceServer NUCservice = nh.advertiseService("FireNUC", NUCService_callback);

    //g_type_init ();

    // Print out some useful info.
    ROS_INFO ("Attached cameras:");
    arv_update_device_list();
    nInterfaces = arv_get_n_interfaces();
    ROS_INFO ("# Interfaces: %d", nInterfaces);

    nDevices = arv_get_n_devices();
    ROS_INFO ("# Devices: %d", nDevices);
    for (i=0; i<nDevices; i++)
    	ROS_INFO ("Device%d: %s", i, arv_get_device_id(i));
    
    if (nDevices>0)
    {
		// Get the camera guid from either the command-line or as a parameter.
    	if (argc==2)
    	{
    		strcpy(szGuid, argv[1]);
    		pszGuid = szGuid;
    	}
    	else
    	{
    		if (global.phNode->hasParam(ros::this_node::getName()+"/guid"))
    		{
    			std::string		stGuid;
    			
    			global.phNode->getParam(ros::this_node::getName()+"/guid", stGuid);
    			strcpy (szGuid, stGuid.c_str());
        		pszGuid = szGuid;
    		}
    		else
    			pszGuid = NULL;
    	}
    	
    	// Open the camera, and set it up.
    	ROS_INFO("Opening: %s", pszGuid ? pszGuid : "(any)");
		while (TRUE)
		{
			global.pCamera = arv_camera_new(pszGuid);
			if (global.pCamera)
				break;
			else
			{
				ROS_WARN ("Could not open camera %s.  Retrying...", pszGuid);
				ros::Duration(1.0).sleep();
			    ros::spinOnce();
			}
		}

		global.pDevice = arv_camera_get_device(global.pCamera);
		ROS_INFO("Opened: %s-%s", arv_device_get_string_feature_value (global.pDevice, "DeviceVendorName"), arv_device_get_string_feature_value (global.pDevice, "DeviceID"));


		// See if some basic camera features exist.
		pGcNode = arv_device_get_feature (global.pDevice, "AcquisitionMode");
		global.isImplementedAcquisitionMode = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "GainRaw");
		global.isImplementedGain = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;
		pGcNode = arv_device_get_feature (global.pDevice, "Gain");
		global.isImplementedGain |= ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "ExposureTimeAbs");
		global.isImplementedExposureTimeAbs = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "ExposureAuto");
		global.isImplementedExposureAuto = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "GainAuto");
		global.isImplementedGainAuto = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "TriggerSelector");
		global.isImplementedTriggerSelector = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "TriggerSource");
		global.isImplementedTriggerSource = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "TriggerMode");
		global.isImplementedTriggerMode = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "FocusPos");
		global.isImplementedFocusPos = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "GevSCPSPacketSize");
		global.isImplementedMtu = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		pGcNode = arv_device_get_feature (global.pDevice, "AcquisitionFrameRateEnable");
		global.isImplementedAcquisitionFrameRateEnable = ARV_GC_FEATURE_NODE (pGcNode) ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;

		// Find the key name for framerate.
		global.keyAcquisitionFrameRate = NULL;
		for (i=0; i<2; i++)
		{
			pGcNode = arv_device_get_feature (global.pDevice, pkeyAcquisitionFrameRate[i]);
			global.isImplementedAcquisitionFrameRate = pGcNode ? arv_gc_feature_node_is_implemented (ARV_GC_FEATURE_NODE (pGcNode), &error) : FALSE;
			if (global.isImplementedAcquisitionFrameRate)
			{
				global.keyAcquisitionFrameRate = pkeyAcquisitionFrameRate[i];
				break;
			}
		}


		// Get parameter bounds.
		arv_camera_get_exposure_time_bounds	(global.pCamera, &global.configMin.ExposureTimeAbs, &global.configMax.ExposureTimeAbs);
		arv_camera_get_gain_bounds			(global.pCamera, &global.configMin.Gain, &global.configMax.Gain);
		arv_camera_get_sensor_size			(global.pCamera, &global.widthSensor, &global.heightSensor);
		arv_camera_get_width_bounds			(global.pCamera, &global.widthRoiMin, &global.widthRoiMax);
		arv_camera_get_height_bounds		(global.pCamera, &global.heightRoiMin, &global.heightRoiMax);

		if (global.isImplementedFocusPos)
		{
			gint64 focusMin64, focusMax64;
			arv_device_get_integer_feature_bounds (global.pDevice, "FocusPos", &focusMin64, &focusMax64);
			global.configMin.FocusPos = focusMin64;
			global.configMax.FocusPos = focusMax64;
		}
		else
		{
			global.configMin.FocusPos = 0;
			global.configMax.FocusPos = 0;
		}

		global.configMin.AcquisitionFrameRate =    0.0;
		global.configMax.AcquisitionFrameRate = 1000.0;


		// Initial camera settings.
		if (global.isImplementedExposureTimeAbs)
			arv_device_set_float_feature_value(global.pDevice, "ExposureTimeAbs", global.config.ExposureTimeAbs);
		if (global.isImplementedGain)
			arv_camera_set_gain(global.pCamera, global.config.Gain);
			//arv_device_set_integer_feature_value(global.pDevice, "GainRaw", global.config.GainRaw);
		if (global.isImplementedAcquisitionFrameRateEnable)
			arv_device_set_integer_feature_value(global.pDevice, "AcquisitionFrameRateEnable", 1);
		if (global.isImplementedAcquisitionFrameRate)
			arv_device_set_float_feature_value(global.pDevice, global.keyAcquisitionFrameRate, global.config.AcquisitionFrameRate);


		// Set up the triggering.
		if (global.isImplementedTriggerMode)
		{
			if (global.isImplementedTriggerSelector && global.isImplementedTriggerMode)
			{
				arv_device_set_string_feature_value(global.pDevice, "TriggerSelector", "AcquisitionStart");
				arv_device_set_string_feature_value(global.pDevice, "TriggerMode", "Off");
				arv_device_set_string_feature_value(global.pDevice, "TriggerSelector", "FrameStart");
				arv_device_set_string_feature_value(global.pDevice, "TriggerMode", "Off");
			}
		}


		WriteCameraFeaturesFromRosparam ();


#ifdef TUNING			
		ros::Publisher pubInt64 = global.phNode->advertise<std_msgs::Int64>(ros::this_node::getName()+"/dt", 100);
		global.ppubInt64 = &pubInt64;
#endif
    	
    // Grab the calibration file url from the param server if exists
    std::string calibrationURL = ""; // Default looks in .ros/camera_info
		if (!(ros::param::get(std::string("calibrationURL").append(arv_device_get_string_feature_value (global.pDevice, "DeviceID")), calibrationURL)))
		{
			ROS_ERROR("ERROR: Could not read calibrationURL from parameter server");
		}

		// Start the camerainfo manager.
		global.pCameraInfoManager = new camera_info_manager::CameraInfoManager(ros::NodeHandle(ros::this_node::getName()), arv_device_get_string_feature_value (global.pDevice, "DeviceID"), calibrationURL);

		// Start the dynamic_reconfigure server.
		dynamic_reconfigure::Server<Config> 				reconfigureServer;
		dynamic_reconfigure::Server<Config>::CallbackType 	reconfigureCallback;

		reconfigureCallback = boost::bind(&RosReconfigure_callback, _1, _2);
		reconfigureServer.setCallback(reconfigureCallback);
		ros::Duration(2.0).sleep();


		// Get parameter current values.
		global.xRoi=0; global.yRoi=0; global.widthRoi=0; global.heightRoi=0;
		arv_camera_get_region (global.pCamera, &global.xRoi, &global.yRoi, &global.widthRoi, &global.heightRoi);
		global.config.ExposureTimeAbs 	= global.isImplementedExposureTimeAbs ? arv_device_get_float_feature_value (global.pDevice, "ExposureTimeAbs") : 0;
		global.config.Gain      		= global.isImplementedGain ? arv_camera_get_gain (global.pCamera) : 0.0;
		global.pszPixelformat   		= g_string_ascii_down(g_string_new(arv_device_get_string_feature_value(global.pDevice, "PixelFormat")))->str;
		global.nBytesPixel      		= ARV_PIXEL_FORMAT_BYTE_PER_PIXEL(arv_device_get_integer_feature_value(global.pDevice, "PixelFormat"));
		global.config.FocusPos  		= global.isImplementedFocusPos ? arv_device_get_integer_feature_value (global.pDevice, "FocusPos") : 0;
		
		
		// Print information.
		ROS_INFO ("    Using Camera Configuration:");
		ROS_INFO ("    ---------------------------");
		ROS_INFO ("    Vendor name          = %s", arv_device_get_string_feature_value (global.pDevice, "DeviceVendorName"));
		ROS_INFO ("    Model name           = %s", arv_device_get_string_feature_value (global.pDevice, "DeviceModelName"));
		ROS_INFO ("    Device id            = %s", arv_device_get_string_feature_value (global.pDevice, "DeviceID"));
		ROS_INFO ("    Sensor width         = %d", global.widthSensor);
		ROS_INFO ("    Sensor height        = %d", global.heightSensor);
		ROS_INFO ("    ROI x,y,w,h          = %d, %d, %d, %d", global.xRoi, global.yRoi, global.widthRoi, global.heightRoi);
		ROS_INFO ("    Pixel format         = %s", global.pszPixelformat);
		ROS_INFO ("    BytesPerPixel        = %d", global.nBytesPixel);
		ROS_INFO ("    Acquisition Mode     = %s", global.isImplementedAcquisitionMode ? arv_device_get_string_feature_value (global.pDevice, "AcquisitionMode") : "(not implemented in camera)");
		ROS_INFO ("    Trigger Mode         = %s", global.isImplementedTriggerMode ? arv_device_get_string_feature_value (global.pDevice, "TriggerMode") : "(not implemented in camera)");
		ROS_INFO ("    Trigger Source       = %s", global.isImplementedTriggerSource ? arv_device_get_string_feature_value(global.pDevice, "TriggerSource") : "(not implemented in camera)");
		ROS_INFO ("    Can set FrameRate:     %s", global.isImplementedAcquisitionFrameRate ? "True" : "False");
		if (global.isImplementedAcquisitionFrameRate)
		{
			global.config.AcquisitionFrameRate = arv_device_get_float_feature_value (global.pDevice, global.keyAcquisitionFrameRate);
			ROS_INFO ("    AcquisitionFrameRate = %g hz", global.config.AcquisitionFrameRate);
		}

		ROS_INFO ("    Can set Exposure:      %s", global.isImplementedExposureTimeAbs ? "True" : "False");
		if (global.isImplementedExposureTimeAbs)
		{
			ROS_INFO ("    Can set ExposureAuto:  %s", global.isImplementedExposureAuto ? "True" : "False");
			ROS_INFO ("    Exposure             = %g us in range [%g,%g]", global.config.ExposureTimeAbs, global.configMin.ExposureTimeAbs, global.configMax.ExposureTimeAbs);
		}

		ROS_INFO ("    Can set Gain:          %s", global.isImplementedGain ? "True" : "False");
		if (global.isImplementedGain)
		{
			ROS_INFO ("    Can set GainAuto:      %s", global.isImplementedGainAuto ? "True" : "False");
			ROS_INFO ("    Gain                 = %f %% in range [%f,%f]", global.config.Gain, global.configMin.Gain, global.configMax.Gain);
		}

		ROS_INFO ("    Can set FocusPos:      %s", global.isImplementedFocusPos ? "True" : "False");

		if (global.isImplementedMtu)
			ROS_INFO ("    Network mtu          = %lu", arv_device_get_integer_feature_value(global.pDevice, "GevSCPSPacketSize"));

		ROS_INFO ("    ---------------------------");


//		// Print the tree of camera features, with their values.
//		ROS_INFO ("    ----------------------------------------------------------------------------------");
//		NODEEX		 nodeex;
//		ArvGc	*pGenicam=0;
//		pGenicam = arv_device_get_genicam(global.pDevice);
//
//		nodeex.szName = "Root";
//		nodeex.pNode = (ArvDomNode	*)arv_gc_get_node(pGenicam, nodeex.szName);
//		nodeex.pNodeSibling = NULL;
//		PrintDOMTree(pGenicam, nodeex, 0);
//		ROS_INFO ("    ----------------------------------------------------------------------------------");
			

		ArvGvStream *pStream = NULL;
		while (TRUE)
		{
			pStream = CreateStream();
			if (pStream)
				break;
			else
			{
				ROS_WARN("Could not create image stream for %s.  Retrying...", pszGuid);
				ros::Duration(1.0).sleep();
			    ros::spinOnce();
			}
		}


		ApplicationData applicationdata;
		applicationdata.nBuffers=0;
		applicationdata.main_loop = 0;

		// Set up image_raw.
		image_transport::ImageTransport		*pTransport = new image_transport::ImageTransport(*global.phNode);
		global.publisher = pTransport->advertiseCamera(ros::this_node::getName()+"/image_raw", 1);

		// Connect signals with callbacks.
		g_signal_connect (pStream,        "new-buffer",   G_CALLBACK (NewBuffer_callback),   &applicationdata);
		g_signal_connect (global.pDevice, "control-lost", G_CALLBACK (ControlLost_callback), NULL);
		g_timeout_add_seconds (1, PeriodicTask_callback, &applicationdata);
		arv_stream_set_emit_signals ((ArvStream *)pStream, TRUE);


		void (*pSigintHandlerOld)(int);
		pSigintHandlerOld = signal (SIGINT, set_cancel);

		arv_device_execute_command (global.pDevice, "AcquisitionStart");

		applicationdata.main_loop = g_main_loop_new (NULL, FALSE);
		g_main_loop_run (applicationdata.main_loop);

		if (global.idSoftwareTriggerTimer)
		{
			g_source_remove(global.idSoftwareTriggerTimer);
			global.idSoftwareTriggerTimer = 0;
		}

		signal (SIGINT, pSigintHandlerOld);

		g_main_loop_unref (applicationdata.main_loop);

		guint64 n_completed_buffers;
		guint64 n_failures;
		guint64 n_underruns;
		guint64 n_resent;
		guint64 n_missing;
		arv_stream_get_statistics ((ArvStream *)pStream, &n_completed_buffers, &n_failures, &n_underruns);
		ROS_INFO ("Completed buffers = %Lu", (unsigned long long) n_completed_buffers);
		ROS_INFO ("Failures          = %Lu", (unsigned long long) n_failures);
		ROS_INFO ("Underruns         = %Lu", (unsigned long long) n_underruns);
		arv_gv_stream_get_statistics (pStream, &n_resent, &n_missing);
		ROS_INFO ("Resent buffers    = %Lu", (unsigned long long) n_resent);
		ROS_INFO ("Missing           = %Lu", (unsigned long long) n_missing);

		arv_device_execute_command (global.pDevice, "AcquisitionStop");

		g_object_unref (pStream);

    }
    else
    	ROS_ERROR ("No cameras detected.");
    
    delete global.phNode;
    
    return 0;
} // main()
static RejillaBurnResult
rejilla_status_dialog_uri_has_image (RejillaTrackDataCfg *track,
				     const gchar *uri,
				     RejillaBurnOptions *self)
{
	gint answer;
	gchar *name;
	GtkWidget *button;
	GtkWidget *dialog;
	gboolean was_visible = FALSE;
	gboolean was_not_ready = FALSE;
	RejillaTrackImageCfg *track_img;
	RejillaBurnOptionsPrivate *priv;

	priv = REJILLA_BURN_OPTIONS_PRIVATE (self);
	dialog = gtk_message_dialog_new (GTK_WINDOW (self),
					 GTK_DIALOG_MODAL |
					 GTK_DIALOG_DESTROY_WITH_PARENT,
					 GTK_MESSAGE_QUESTION,
					 GTK_BUTTONS_NONE,
					 "%s",
					 _("Do you want to create a disc from the contents of the image or with the image file inside?"));

	gtk_window_set_title (GTK_WINDOW (dialog), "");
	gtk_window_set_icon_name (GTK_WINDOW (dialog),
	                          gtk_window_get_icon_name (GTK_WINDOW (self)));

	name = rejilla_utils_get_uri_name (uri);
	gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
			/* Translators: %s is the name of the image */
			_("There is only one selected file (\"%s\"). "
			  "It is the image of a disc and its contents can be burned."),
			name);
	g_free (name);

	gtk_dialog_add_button (GTK_DIALOG (dialog), _("Burn as _File"), GTK_RESPONSE_NO);

	button = rejilla_utils_make_button (_("Burn _Contents…"),
	                                    NULL,
	                                    "media-optical-burn",
	                                    GTK_ICON_SIZE_BUTTON);
	gtk_widget_show (button);
	gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
				      button,
				      GTK_RESPONSE_YES);

	if (!priv->not_ready_id && priv->status_dialog) {
		was_visible = TRUE;
		gtk_widget_hide (GTK_WIDGET (priv->status_dialog));
	}
	else if (priv->not_ready_id) {
		g_source_remove (priv->not_ready_id);
		priv->not_ready_id = 0;
		was_not_ready = TRUE;
	}

	gtk_widget_show_all (dialog);
	answer = gtk_dialog_run (GTK_DIALOG (dialog));
	gtk_widget_destroy (dialog);

	if (answer != GTK_RESPONSE_YES) {
		if (was_not_ready)
			priv->not_ready_id = g_timeout_add_seconds (1,
								    rejilla_burn_options_not_ready_dialog_show_cb,
								    self);
		if (was_visible)
			gtk_widget_show (GTK_WIDGET (priv->status_dialog));

		return REJILLA_BURN_OK;
	}

	/* Setup a new track and add it to session */
	track_img = rejilla_track_image_cfg_new ();
	rejilla_track_image_cfg_set_source (track_img, uri);
	rejilla_burn_session_add_track (REJILLA_BURN_SESSION (priv->session),
					REJILLA_TRACK (track_img),
					NULL);

	return REJILLA_BURN_CANCEL;
}
示例#18
0
文件: device.c 项目: BloodLiker/bluez
static void device_remove_control_timer(struct audio_device *dev)
{
	if (dev->priv->control_timer)
		g_source_remove(dev->priv->control_timer);
	dev->priv->control_timer = 0;
}
示例#19
0
static void decode_msg(void *base, size_t len, struct timeval *tv,
		struct timespec *mrx_time)
{
	struct ntp_msg *msg = base;
	double m_delta, org, rec, xmt, dst;
	double delay, offset;
	static guint transmit_delay;

	if (len < sizeof(*msg)) {
		connman_error("Invalid response from time server");
		return;
	}

	if (tv == NULL) {
		connman_error("Invalid packet timestamp from time server");
		return;
	}

	DBG("flags      : 0x%02x", msg->flags);
	DBG("stratum    : %u", msg->stratum);
	DBG("poll       : %f seconds (%d)",
				LOGTOD(msg->poll), msg->poll);
	DBG("precision  : %f seconds (%d)",
				LOGTOD(msg->precision), msg->precision);
	DBG("root delay : %u seconds (fraction %u)",
			msg->rootdelay.seconds, msg->rootdelay.fraction);
	DBG("root disp. : %u seconds (fraction %u)",
			msg->rootdisp.seconds, msg->rootdisp.fraction);
	DBG("reference  : 0x%04x", msg->refid);

	transmit_delay = LOGTOD(msg->poll);

	if (NTP_FLAGS_LI_DECODE(msg->flags) == NTP_FLAG_LI_NOTINSYNC) {
		DBG("ignoring unsynchronized peer");
		return;
	}

	if (NTP_FLAGS_VN_DECODE(msg->flags) != 4) {
		DBG("unsupported version %d", NTP_FLAGS_VN_DECODE(msg->flags));
		return;
	}

	if (NTP_FLAGS_MD_DECODE(msg->flags) != NTP_FLAG_MD_SERVER) {
		DBG("unsupported mode %d", NTP_FLAGS_MD_DECODE(msg->flags));
		return;
	}

	m_delta = mrx_time->tv_sec - mtx_time.tv_sec +
		1.0e-9 * (mrx_time->tv_nsec - mtx_time.tv_nsec);

	org = tv->tv_sec + (1.0e-6 * tv->tv_usec) - m_delta + OFFSET_1900_1970;
	rec = ntohl(msg->rectime.seconds) +
			((double) ntohl(msg->rectime.fraction) / UINT_MAX);
	xmt = ntohl(msg->xmttime.seconds) +
			((double) ntohl(msg->xmttime.fraction) / UINT_MAX);
	dst = tv->tv_sec + (1.0e-6 * tv->tv_usec) + OFFSET_1900_1970;

	DBG("org=%f rec=%f xmt=%f dst=%f", org, rec, xmt, dst);

	offset = ((rec - org) + (xmt - dst)) / 2;
	delay = (dst - org) - (xmt - rec);

	DBG("offset=%f delay=%f", offset, delay);

	/* Remove the timeout, as timeserver has responded */

	reset_timeout();

	/*
	 * Now poll the server every transmit_delay seconds
	 * for time correction.
	 */
	if (poll_id > 0)
		g_source_remove(poll_id);

	DBG("Timeserver %s, next sync in %d seconds", timeserver, transmit_delay);

	poll_id = g_timeout_add_seconds(transmit_delay, next_poll, NULL);

	connman_info("ntp: time slew %+.6f s", offset);

	if (offset < STEPTIME_MIN_OFFSET && offset > -STEPTIME_MIN_OFFSET) {
		struct timeval adj;

		adj.tv_sec = (long) offset;
		adj.tv_usec = (offset - adj.tv_sec) * 1000000;

		DBG("adjusting time");

		if (adjtime(&adj, &adj) < 0) {
			connman_error("Failed to adjust time");
			return;
		}

		DBG("%lu seconds, %lu msecs", adj.tv_sec, adj.tv_usec);
	} else {
		struct timeval cur;
		double dtime;

		gettimeofday(&cur, NULL);
		dtime = offset + cur.tv_sec + 1.0e-6 * cur.tv_usec;
		cur.tv_sec = (long) dtime;
		cur.tv_usec = (dtime - cur.tv_sec) * 1000000;

		DBG("setting time");

		if (settimeofday(&cur, NULL) < 0) {
			connman_error("Failed to set time");
			return;
		}

		DBG("%lu seconds, %lu msecs", cur.tv_sec, cur.tv_usec);
	}
}
示例#20
0
文件: device.c 项目: BloodLiker/bluez
static void device_remove_avdtp_timer(struct audio_device *dev)
{
	if (dev->priv->avdtp_timer)
		g_source_remove(dev->priv->avdtp_timer);
	dev->priv->avdtp_timer = 0;
}
示例#21
0
static void on_video_window_destroy(GtkWidget *w, guint timeout){
	g_source_remove(timeout);
	linphone_core_set_native_video_window_id(linphone_gtk_get_core(),LINPHONE_VIDEO_DISPLAY_NONE);
}
示例#22
0
文件: device.c 项目: BloodLiker/bluez
static void device_remove_headset_timer(struct audio_device *dev)
{
	if (dev->priv->headset_timer)
		g_source_remove(dev->priv->headset_timer);
	dev->priv->headset_timer = 0;
}
示例#23
0
void
cb_change_current_page (GtkNotebook *nb, gint num, gpointer data)
{
    ProcData * const procdata = static_cast<ProcData*>(data);

    procdata->config.current_tab = num;


    if (num == PROCMAN_TAB_PROCESSES) {

        cb_timeout (procdata);

        if (!procdata->timeout)
            procdata->timeout = g_timeout_add (
                procdata->config.update_interval,
                cb_timeout, procdata);

        update_sensitivity(procdata);
    }
    else {
        if (procdata->timeout) {
            g_source_remove (procdata->timeout);
            procdata->timeout = 0;
        }

        update_sensitivity(procdata);
    }


    if (num == PROCMAN_TAB_RESOURCES) {
        load_graph_start (procdata->cpu_graph);
        load_graph_start (procdata->mem_graph);
        load_graph_start (procdata->net_graph);
    }
    else {
        load_graph_stop (procdata->cpu_graph);
        load_graph_stop (procdata->mem_graph);
        load_graph_stop (procdata->net_graph);
    }


    if (num == PROCMAN_TAB_DISKS) {

        cb_update_disks (procdata);

        if(!procdata->disk_timeout) {
            procdata->disk_timeout =
                g_timeout_add (procdata->config.disks_update_interval,
                           cb_update_disks,
                           procdata);
        }
    }
    else {
        if(procdata->disk_timeout) {
            g_source_remove (procdata->disk_timeout);
            procdata->disk_timeout = 0;
        }
    }

    if (num == PROCMAN_TAB_SYSINFO) {
        procman::build_sysinfo_ui();
    }
}
示例#24
0
/*
 *	Add an Signal to the gmainloop world...
 */
GSIGSource*
G_main_add_SignalHandler(int priority, int signal,
			 gboolean (*dispatch)(int nsig, gpointer user_data),
			 gpointer userdata, GDestroyNotify notify)
{
	GSIGSource* sig_src;
	GSource * source = g_source_new(&G_SIG_SourceFuncs, sizeof(GSIGSource));
	gboolean failed = FALSE;
	
	sig_src = (GSIGSource*)source;
	
	sig_src->magno		= MAG_GSIGSOURCE;
	sig_src->maxdispatchdelayms = DEFAULT_MAXDELAY;
	sig_src->maxdispatchms	= DEFAULT_MAXDISPATCH;
	sig_src->signal		= signal;
	sig_src->dispatch	= dispatch;
	sig_src->udata		= userdata;
	sig_src->dnotify	= notify;

	sig_src->signal_triggered = FALSE;

	g_source_set_priority(source, priority);
	g_source_set_can_recurse(source, FALSE);

	if(G_main_signal_list[signal] != NULL) {
		cl_log(LOG_ERR
		,	"%s: Handler already present for signal %d"
		,	__FUNCTION__, signal);
		failed = TRUE;
	}
	if(!failed) {
		sig_src->gsourceid = g_source_attach(source, NULL);
		sig_src->description = "signal";
		if (sig_src->gsourceid < 1) {
			cl_log(LOG_ERR
			,	"%s: Could not attach source for signal %d (%d)"
			,	__FUNCTION__
			,	signal, sig_src->gsourceid);
			failed = TRUE;
		}
	}
	
	if(failed) {
		cl_log(LOG_ERR
		,	"%s: Signal handler for signal %d NOT added"
		,	__FUNCTION__, signal);
		g_source_remove(sig_src->gsourceid);
		g_source_unref(source);
		source = NULL;
		sig_src = NULL;
	} else {
		if (debug_level > 1) {
			cl_log(LOG_DEBUG
			, "%s: Added signal handler for signal %d"
			,	__FUNCTION__, signal);
		}
		G_main_signal_list[signal] = sig_src;
		CL_SIGNAL(signal, G_main_signal_handler);
		/*
		 * If we don't set this on, then the mainloop poll(2) call
		 * will never be interrupted by this signal - which sort of
		 * defeats the whole purpose of a signal handler in a
		 * mainloop program
		 */
		cl_signal_set_interrupt(signal, TRUE);
	}
	return sig_src;
}
gboolean
gimp_container_tree_view_drag_motion (GtkWidget             *widget,
                                      GdkDragContext        *context,
                                      gint                   x,
                                      gint                   y,
                                      guint                  time,
                                      GimpContainerTreeView *tree_view)
{
  GtkTreePath             *path;
  GtkTreeViewDropPosition  drop_pos;

  if (y < SCROLL_DISTANCE || y > (widget->allocation.height - SCROLL_DISTANCE))
    {
      gint distance;

      if (y < SCROLL_DISTANCE)
        {
          tree_view->scroll_dir = GDK_SCROLL_UP;
          distance = MIN (-y, -1);
        }
      else
        {
          tree_view->scroll_dir = GDK_SCROLL_DOWN;
          distance = MAX (widget->allocation.height - y, 1);
        }

      tree_view->scroll_timeout_interval = SCROLL_INTERVAL * ABS (distance);

#ifdef SCROLL_DEBUG
      g_print ("drag_motion: scroll_distance = %d  scroll_interval = %d\n",
               distance, tree_view->scroll_timeout_interval);
#endif

      if (! tree_view->scroll_timeout_id)
        tree_view->scroll_timeout_id =
          g_timeout_add (tree_view->scroll_timeout_interval,
                         gimp_container_tree_view_scroll_timeout,
                         tree_view);
    }
  else if (tree_view->scroll_timeout_id)
    {
      g_source_remove (tree_view->scroll_timeout_id);
      tree_view->scroll_timeout_id = 0;
    }

  if (gimp_container_tree_view_drop_status (tree_view,
                                            context, x, y, time,
                                            &path, NULL, NULL, NULL, NULL,
                                            &drop_pos))
    {
      gtk_tree_view_set_drag_dest_row (tree_view->view, path, drop_pos);
      gtk_tree_path_free (path);
    }
  else
    {
      gtk_tree_view_set_drag_dest_row (tree_view->view, NULL, 0);
    }

  /*  always return TRUE so drag_leave() is called  */
  return TRUE;
}
示例#26
0
 ~DownloadClient()
 {
     if (m_handleResponseLaterID)
         g_source_remove(m_handleResponseLaterID);
 }
示例#27
0
文件: dcc-get.c 项目: Adam-/irssi
/* callback: net_connect() finished for DCC GET */
void sig_dccget_connected(GET_DCC_REC *dcc)
{
	struct stat statbuf;
	char *fname, *tempfname, *str;
        int ret, ret_errno, temphandle, old_umask;

	if (!dcc->from_dccserver) {
		if (net_geterror(dcc->handle) != 0) {
			/* error connecting */
			signal_emit("dcc error connect", 1, dcc);
			dcc_destroy(DCC(dcc));
			return;
		}

		g_source_remove(dcc->tagconn);
		dcc->tagconn = -1;
	}

	g_free_not_null(dcc->file);
	dcc->file = dcc_get_download_path(dcc->arg);

	/* if some plugin wants to change the file name/path here.. */
	signal_emit("dcc get receive", 1, dcc);

	if (stat(dcc->file, &statbuf) == 0 &&
	    dcc->get_type == DCC_GET_RENAME) {
		/* file exists, rename.. */
		fname = dcc_get_rename_file(dcc->file);
		g_free(dcc->file);
		dcc->file = fname;
	}

	if (dcc->get_type != DCC_GET_RESUME) {
		int dcc_file_create_mode = octal2dec(settings_get_int("dcc_file_create_mode"));

		/* we want to overwrite the file, remove it here.
		   if it gets created after this, we'll fail. */
		unlink(dcc->file);

		/* just to make sure we won't run into race conditions
		   if download_path is in some global temp directory */
		tempfname = g_strconcat(dcc->file, ".XXXXXX", NULL);

                old_umask = umask(0077);
		temphandle = mkstemp(tempfname);
		umask(old_umask);

		if (temphandle == -1)
			ret = -1;
		else
			ret = fchmod(temphandle, dcc_file_create_mode);

		if (ret != -1) {
			ret = link(tempfname, dcc->file);

			if (ret == -1 &&
			    /* Linux */
			    (errno == EPERM ||
			     /* FUSE */
			     errno == ENOSYS ||
			     /* BSD */
			     errno == EOPNOTSUPP)) {
				/* hard links aren't supported - some people
				   want to download stuff to FAT/NTFS/etc
				   partitions, so fallback to rename() */
				ret = rename(tempfname, dcc->file);
			}
		}

		/* if ret = 0, we're the file owner now */
		dcc->fhandle = ret == -1 ? -1 :
			open(dcc->file, O_WRONLY | O_TRUNC);

		/* close/remove the temp file */
		ret_errno = errno;
		close(temphandle);
		unlink(tempfname);
		g_free(tempfname);

		if (dcc->fhandle == -1) {
			signal_emit("dcc error file create", 3,
				    dcc, dcc->file, g_strerror(ret_errno));
			dcc_destroy(DCC(dcc));
			return;
		}
	}

	dcc->starttime = time(NULL);
	if (dcc->size == 0) {
		dcc_close(DCC(dcc));
		return;
	}
	dcc->tagread = g_input_add(dcc->handle, G_INPUT_READ,
				   (GInputFunction) sig_dccget_receive, dcc);
	signal_emit("dcc connected", 1, dcc);

	if (dcc->from_dccserver) {
		str = g_strdup_printf("121 %s %d\n",
				      dcc->server ? dcc->server->nick : "??", 0);
		net_transmit(dcc->handle, str, strlen(str));
	}
}
void
e_task_shell_view_private_dispose (ETaskShellView *task_shell_view)
{
	ETaskShellViewPrivate *priv = task_shell_view->priv;

	if (priv->client_added_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->task_shell_sidebar,
			priv->client_added_handler_id);
		priv->client_added_handler_id = 0;
	}

	if (priv->client_removed_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->task_shell_sidebar,
			priv->client_removed_handler_id);
		priv->client_removed_handler_id = 0;
	}

	if (priv->backend_error_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->client_cache,
			priv->backend_error_handler_id);
		priv->backend_error_handler_id = 0;
	}

	if (priv->open_component_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->task_table,
			priv->open_component_handler_id);
		priv->open_component_handler_id = 0;
	}

	if (priv->popup_event_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->task_table,
			priv->popup_event_handler_id);
		priv->popup_event_handler_id = 0;
	}

	if (priv->selection_change_1_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->task_table,
			priv->selection_change_1_handler_id);
		priv->selection_change_1_handler_id = 0;
	}

	if (priv->selection_change_2_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->task_table,
			priv->selection_change_2_handler_id);
		priv->selection_change_2_handler_id = 0;
	}

	if (priv->status_message_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->task_table,
			priv->status_message_handler_id);
		priv->status_message_handler_id = 0;
	}

	if (priv->model_changed_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->model,
			priv->model_changed_handler_id);
		priv->model_changed_handler_id = 0;
	}

	if (priv->model_rows_deleted_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->model,
			priv->model_rows_deleted_handler_id);
		priv->model_rows_deleted_handler_id = 0;
	}

	if (priv->model_rows_inserted_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->model,
			priv->model_rows_inserted_handler_id);
		priv->model_rows_inserted_handler_id = 0;
	}

	if (priv->rows_appended_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->model,
			priv->rows_appended_handler_id);
		priv->rows_appended_handler_id = 0;
	}

	if (priv->selector_popup_event_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->selector,
			priv->selector_popup_event_handler_id);
		priv->selector_popup_event_handler_id = 0;
	}

	if (priv->primary_selection_changed_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->selector,
			priv->primary_selection_changed_handler_id);
		priv->primary_selection_changed_handler_id = 0;
	}

	if (priv->settings_hide_completed_tasks_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->settings,
			priv->settings_hide_completed_tasks_handler_id);
		priv->settings_hide_completed_tasks_handler_id = 0;
	}

	if (priv->settings_hide_completed_tasks_units_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->settings,
			priv->settings_hide_completed_tasks_units_handler_id);
		priv->settings_hide_completed_tasks_units_handler_id = 0;
	}

	if (priv->settings_hide_completed_tasks_value_handler_id > 0) {
		g_signal_handler_disconnect (
			priv->settings,
			priv->settings_hide_completed_tasks_value_handler_id);
		priv->settings_hide_completed_tasks_value_handler_id = 0;
	}

	g_clear_object (&priv->task_shell_backend);
	g_clear_object (&priv->task_shell_content);
	g_clear_object (&priv->task_shell_sidebar);

	g_clear_object (&priv->client_cache);
	g_clear_object (&priv->task_table);
	g_clear_object (&priv->model);
	g_clear_object (&priv->selector);
	g_clear_object (&priv->settings);

	if (task_shell_view->priv->activity != NULL) {
		/* XXX Activity is not cancellable. */
		e_activity_set_state (
			task_shell_view->priv->activity,
			E_ACTIVITY_COMPLETED);
		g_object_unref (task_shell_view->priv->activity);
		task_shell_view->priv->activity = NULL;
	}

	if (priv->update_timeout > 0) {
		g_source_remove (priv->update_timeout);
		priv->update_timeout = 0;
	}

	if (priv->update_completed_timeout > 0) {
		g_source_remove (priv->update_completed_timeout);
		priv->update_completed_timeout = 0;
	}
}
void
mb_kbd_key_press (MBKeyboardKey *key)
{
  /* XXX what about state handling XXX */
  MBKeyboardKeyStateType state;
  int                    flags = 0;
  boolean                queue_full_kbd_redraw = False;

  if (mb_kbd_key_is_blank(key))
    return;

  state = mb_kbd_keys_current_state(key->kbd);

  if (mb_kbd_has_state(key->kbd, MBKeyboardStateCaps)
      && mb_kbd_key_get_obey_caps(key))
    state = MBKeyboardKeyStateShifted;

  /* XXX below fakekey mods probably better in ui */
  if (state == MBKeyboardKeyStateShifted ||
      mb_kbd_has_state(key->kbd, MBKeyboardStateShifted))
    flags |= FAKEKEYMOD_SHIFT;

  if (mb_kbd_has_state(key->kbd, MBKeyboardStateControl))
    flags |= FAKEKEYMOD_CONTROL;

  if (mb_kbd_has_state(key->kbd, MBKeyboardStateAlt))
    flags |= FAKEKEYMOD_ALT;

  if (mb_kbd_has_state(key->kbd, MBKeyboardStateMod1))
    flags |= FAKEKEYMOD_META;

  if (!mb_kdb_key_has_state(key, state))
    {
      if (state == MBKeyboardKeyStateNormal)
	return;  /* keys should at least have a normal state */
      else
        state = MBKeyboardKeyStateNormal;
    }

  /*
   * The only key that sends key events on press is backspace, everything
   * else sends on release.
   */
  switch (mb_kbd_key_get_action_type(key, state))
    {
    case MBKeyboardKeyActionGlyph:
      {
	const char *key_char;

	if ((key_char = mb_kbd_key_get_char_action(key, state)) != NULL)
	  {
	    mb_kbd_set_held_key(key->kbd, key);
	  }
	break;
      }
    case MBKeyboardKeyActionXKeySym:
      {
	KeySym ks;
	if ((ks = mb_kbd_key_get_keysym_action(key, state)) != None)
	  {
            /* Only backspace sends on press and has autorepeat */
            switch (ks)
              {
              case XK_BackSpace:
                mb_kbd_ui_send_keysym_press(key->kbd->ui, ks, flags);
                break;
              default:;
              }

	    mb_kbd_set_held_key(key->kbd, key);
	  }
	break;
      }
    case MBKeyboardKeyActionModifier:
      {

	switch ( mb_kbd_key_get_modifer_action(key, state) )
	  {
	  case MBKeyboardKeyModShift:
	    queue_full_kbd_redraw = True;
#if WANT_GTK_WIDGET
           if (key->press_flag)
              {
                /*
                 * Keyboard is in caps state because of previous long shift
                 * press; toggle the caps; do nothing with the shift key.
                 */
                mb_kbd_toggle_state (key->kbd, MBKeyboardStateCaps);
              }
            else
              {
                if (key->press_timeout)
                  g_source_remove (key->press_timeout);

                /*
                 * Normal press on Shift; toggle the shift key state, then
                 * store the key so we can handle it correctly in the release
                 * function.
                 */
                mb_kbd_toggle_state(key->kbd, MBKeyboardStateShifted);

                /*
                 * If Shift was just enabled we want to look for the long press.
                 * If Shift is being toggled off, we are done.
                 */
                if (mb_kbd_has_state(key->kbd, MBKeyboardStateShifted))
                  {
                    mb_kbd_set_held_key(key->kbd, key);

                    /*
                     * Add timeout to detect long press.
                     */
                    key->press_timeout =
                      g_timeout_add (700, mb_kbd_key_shift_timeout, key);
                  }
              }

            key->press_flag = FALSE;
#else
            mb_kbd_toggle_state(key->kbd, MBKeyboardStateShifted);
            mb_kbd_set_held_key(key->kbd, key);
#endif
	    break;
	  case MBKeyboardKeyModMod1:
	    mb_kbd_toggle_state(key->kbd, MBKeyboardStateMod1);
	    mb_kbd_set_held_key(key->kbd, key);
	    queue_full_kbd_redraw = True;
	    break;
	  case MBKeyboardKeyModMod2:
	    mb_kbd_toggle_state(key->kbd, MBKeyboardStateMod2);
	    mb_kbd_set_held_key(key->kbd, key);
	    queue_full_kbd_redraw = True;
	    break;
	  case MBKeyboardKeyModMod3:
	    mb_kbd_toggle_state(key->kbd, MBKeyboardStateMod3);
	    mb_kbd_set_held_key(key->kbd, key);
	    queue_full_kbd_redraw = True;
	    break;
	  case MBKeyboardKeyModCaps:
	    mb_kbd_toggle_state(key->kbd, MBKeyboardStateCaps);
	    queue_full_kbd_redraw = True;
	    break;
	  case MBKeyboardKeyModControl:
	    mb_kbd_toggle_state(key->kbd, MBKeyboardStateControl);
	    mb_kbd_set_held_key(key->kbd, key);
	    break;
	  case MBKeyboardKeyModAlt:
	    mb_kbd_toggle_state(key->kbd, MBKeyboardStateAlt);
            mb_kbd_set_held_key(key->kbd, key);
	    break;
	  default:
	    DBG("unknown modifier action");
	    break;
	  }

	/* we dont actually have to send a key sym here - but should we ?
         *
         * Also we dont set a held key, as we've changed the keyboard
         * state instead.
	*/
	break;
      }

    default:
      break;
    }

  if (queue_full_kbd_redraw)
    mb_kbd_redraw(key->kbd);
  else
    mb_kbd_redraw_key(key->kbd, key);
}
static void
_bus_handler (GstBus * bus, GstMessage * message,
    GstValidatePipelineMonitor * monitor)
{
  GError *err = NULL;
  gchar *debug = NULL;

  switch (GST_MESSAGE_TYPE (message)) {
    case GST_MESSAGE_ERROR:
      gst_message_parse_error (message, &err, &debug);

      if (g_error_matches (err, GST_CORE_ERROR, GST_CORE_ERROR_MISSING_PLUGIN)) {
        GST_VALIDATE_REPORT (monitor, MISSING_PLUGIN,
            "Error: %s -- Debug message: %s", err->message, debug);
      } else {
        GST_VALIDATE_REPORT (monitor, ERROR_ON_BUS,
            "Got error: %s -- Debug message: %s", err->message, debug);
      }
      GST_VALIDATE_MONITOR_LOCK (monitor);
      monitor->got_error = TRUE;
      GST_VALIDATE_MONITOR_UNLOCK (monitor);
      g_error_free (err);
      g_free (debug);
      break;
    case GST_MESSAGE_WARNING:
      gst_message_parse_warning (message, &err, &debug);
      GST_VALIDATE_REPORT (monitor, WARNING_ON_BUS,
          "Got warning: %s -- Debug message: %s", err->message, debug);
      g_error_free (err);
      g_free (debug);
      break;
    case GST_MESSAGE_STATE_CHANGED:
    {
      if (GST_MESSAGE_SRC (message) == GST_VALIDATE_MONITOR (monitor)->target) {
        GstState oldstate, newstate, pending;

        gst_message_parse_state_changed (message, &oldstate, &newstate,
            &pending);

        if (oldstate == GST_STATE_READY && newstate == GST_STATE_PAUSED) {
          monitor->print_pos_srcid =
              g_timeout_add (PRINT_POSITION_TIMEOUT,
              (GSourceFunc) print_position, monitor);
        } else if (oldstate >= GST_STATE_PAUSED && newstate <= GST_STATE_READY) {
          if (monitor->print_pos_srcid
              && g_source_remove (monitor->print_pos_srcid))
            monitor->print_pos_srcid = 0;
          monitor->got_error = FALSE;
        }
      }

      break;
    }
    case GST_MESSAGE_BUFFERING:
    {
      GstBufferingMode mode;
      gint percent;

      gst_message_parse_buffering (message, &percent);
      gst_message_parse_buffering_stats (message, &mode, NULL, NULL, NULL);

      if (percent == 100) {
        /* a 100% message means buffering is done */
        if (monitor->buffering) {
          monitor->print_pos_srcid =
              g_timeout_add (PRINT_POSITION_TIMEOUT,
              (GSourceFunc) print_position, monitor);
          monitor->buffering = FALSE;
        }
      } else {
        /* buffering... */
        if (!monitor->buffering) {
          monitor->buffering = TRUE;
          if (monitor->print_pos_srcid
              && g_source_remove (monitor->print_pos_srcid))
            monitor->print_pos_srcid = 0;
        }
      }
      break;
    }
    default:
      break;
  }
}