Example #1
0
/* Zoom - to region */
int zoom_region(void)
{
    struct Cell_head win;
    char *mapset;

    G_debug(2, "zoom_region()");

    driver_open();

    mapset = G_find_file2("windows", var_getc(VAR_ZOOM_REGION), NULL);
    if (mapset == NULL) {
	G_warning(_("Cannot find window '%s'"), var_getc(VAR_ZOOM_REGION));
	return 0;
    }
    G__get_window(&win, "windows", var_getc(VAR_ZOOM_REGION), mapset);
    G_put_window(&win);
    G_set_window(&win);

    display_redraw();

    driver_close();

    G_debug(3, "zoom_region(): End");

    return 1;
}
static void
free_orientation_data (SensorData *data)
{
	guint i;

	if (data == NULL)
		return;

	if (data->name_id != 0) {
		g_bus_unown_name (data->name_id);
		data->name_id = 0;
	}

	for (i = 0; i < NUM_SENSOR_TYPES; i++) {
		if (driver_type_exists (data, i))
			driver_close (DRIVER_FOR_TYPE(i));
		g_clear_object (&DEVICE_FOR_TYPE(i));
		g_clear_pointer (&data->clients[i], g_hash_table_unref);
	}

	g_clear_pointer (&data->introspection_data, g_dbus_node_info_unref);
	g_clear_object (&data->connection);
	g_clear_pointer (&data->loop, g_main_loop_unref);
	g_free (data);
}
Example #3
0
/*===========================================================================*
 *				driver_shutdown				     *
 *===========================================================================*/
void driver_shutdown(void)
{
    /* Clean up. */

#if DEBUG
    printf("Filter: %u driver deaths, %u protocol errors, "
           "%u data errors\n", problem_stats[BD_DEAD],
           problem_stats[BD_PROTO], problem_stats[BD_DATA]);
#endif

    if(driver_close(DRIVER_MAIN) != OK)
        printf("Filter: BDEV_CLOSE failed on shutdown (1)\n");

    if(USE_MIRROR)
        if(driver_close(DRIVER_BACKUP) != OK)
            printf("Filter: BDEV_CLOSE failed on shutdown (2)\n");
}
Example #4
0
void session_kill(session_t *session)
{
  if(session->is_shutdown)
  {
    LOG_WARNING("Tried to kill a session that's already dead: %d\n", session->id);
    return;
  }

  session->is_shutdown = TRUE;
  driver_close(session->driver);
}
Example #5
0
/* Zoom - default region */
int zoom_default(void)
{
    struct Cell_head defwin;

    G_debug(2, "zoom_default()");

    driver_open();

    G_get_default_window(&defwin);
    G_put_window(&defwin);
    G_set_window(&defwin);

    display_redraw();

    driver_close();

    G_debug(3, "zoom_default(): End");

    return 1;
}
Example #6
0
/* Zoom - in / out (centre unchanged) */
int zoom_centre(double factor)
{
    double xc, yc, dx, dy;

    G_debug(2, "zoom_centre()");

    driver_open();

    G_debug(2, "1 n = %f s = %f", window.north, window.south);

    dx = (window.east - window.west) / 2;
    dy = (window.north - window.south) / 2;
    xc = (window.east + window.west) / 2;
    yc = (window.north + window.south) / 2;

    G_debug(2, "  yc = %f dy = %f", yc, dy);

    window.north = yc + dy * factor;
    window.south = yc - dy * factor;
    window.east = xc + dx * factor;
    window.west = xc - dx * factor;


    G_debug(2, "2 n = %f s = %f", window.north, window.south);
    G_adjust_Cell_head(&window, 0, 0);
    G_debug(2, "3 n = %f s = %f", window.north, window.south);
    G_put_window(&window);
    G_set_window(&window);

    display_redraw();

    driver_close();

    G_debug(3, "zoom_centre(): End");

    return 1;
}
Example #7
0
File: s725get.c Project: ra1fh/s725
int
main(int argc, char **argv)
{
	struct			  stat s;
	char			  path[PATH_MAX];
	char			  inipath[PATH_MAX];
	const char		 *opt_directory_name = NULL;
	const char		 *opt_driver_name = NULL;
	int				  opt_driver_type = DRIVER_SERIAL;
	const char		 *opt_device_name = NULL;
	int				  opt_format_list[5] = { 0 /* FORMAT_UNKNOWN */ };
	int				  opt_format_index = 0;
	BUF				 *files;
	int				  opt_time = 0;
	int				  opt_user = 0;
	int				  opt_listen = 0;
	int				  ch;
	int				  ok;
	char			 *ap;
	int				  format;
	int				  ret;
	int				  i;

	snprintf(inipath, PATH_MAX, "%s/.s725rc", getenv("HOME"));
	yyin = fopen(inipath, "r");
	if (yyin != NULL) {
		conf_filename = inipath;
		ret = yyparse();
		if (ret != 0)
			exit(1);
		if (conf_driver_type != DRIVER_UNKNOWN)
			opt_driver_type = conf_driver_type;
		if (conf_format_type != FORMAT_UNKNOWN)
			opt_format_list[opt_format_index] = conf_format_type;
		if (conf_device_name != NULL)
			opt_device_name = conf_device_name;
		if (conf_directory_name != NULL)
			opt_directory_name = conf_directory_name;
	}

	while ((ch = getopt(argc, argv, "d:D:f:hlo:rtuv")) != -1) {
		switch (ch) {
		case 'd':
			opt_driver_name = optarg;
			opt_driver_type = driver_name_to_type(opt_driver_name);
			if (opt_driver_type == DRIVER_UNKNOWN)
				fatalx("unknown driver type: %s", opt_driver_name);
			break;
		case 'D':
			opt_device_name = optarg;
			break;
		case 'f':
			opt_directory_name = optarg;
			break;
		case 'l':
			opt_listen = 1;
			break;
		case 'o':
			ap = optarg;
			if (opt_format_index < (sizeof(opt_format_list) /
									sizeof(opt_format_list[0]))) {
				if ((format = format_from_str(ap)) != FORMAT_UNKNOWN)
					opt_format_list[opt_format_index++] = format;
				else
					fatalx("unknown output format: %s", ap);
			}
			break;
		case 't':
			opt_time = 1;
			break;
		case 'u':
			opt_user = 1;
			break;
		case 'v':
			log_add_level();
			break;
		case 'h':
			usage();
			return 0;
			break;
		default:
			usage();
			return 1;
		}
	}

	if (opt_driver_type == DRIVER_SERIAL) {
		if (!opt_device_name)
			fatalx("device name required for %s driver",
				   driver_type_to_name(opt_driver_type));
	}

	if (! (opt_time || opt_user)) {
		if (opt_format_list[0] == FORMAT_UNKNOWN)
			fatalx("no output format specified");
	}

	for (i = 0; i < sizeof(opt_format_list) / sizeof(opt_format_list[0]); ++i) {
		log_info("format: %s", format_to_str(opt_format_list[i]));
	}

	log_info("driver name: %s", driver_type_to_name(opt_driver_type));
	log_info("driver type: %d", opt_driver_type);
	log_info("device name: %s", opt_device_name ? opt_device_name : "");
	log_info("directory name: %s", opt_directory_name ? opt_directory_name : "");

	ok = driver_init(opt_driver_type, opt_device_name);
	if (ok != 1)
		fatalx("driver_init failed");

	if (opt_directory_name) {
		opt_directory_name = realpath(opt_directory_name, path);
	} else {
		getcwd(path, sizeof(path));
		opt_directory_name = path;
	}

	if (!opt_directory_name)
		fatalx("could not resolve path. check -f");

	if (access(opt_directory_name, R_OK | W_OK | X_OK) != 0)
		fatalx("unable to access directory: %s", opt_directory_name);

	if (stat(opt_directory_name, &s) != 0)
		fatalx("unable to stat directory: %s", opt_directory_name);

	if (! S_ISDIR(s.st_mode))
		fatalx("not a directory directory: %s", opt_directory_name);

	if (driver_open() < 0)
		fatalx("unable to open port: %s", strerror(errno));

	if (opt_time) {
		time_get();
		driver_close();
		return 0;
	}

	if (opt_user) {
		user_get();
		driver_close();
		return 0;
	}

	files = buf_alloc(0);

	if (opt_listen) {
		ret = files_listen(files);
	} else {
		ret = files_get(files);
	}

	if (ret) {
		for (i = 0; i < sizeof(opt_format_list) / sizeof(opt_format_list[0]); ++i) {
			if (opt_format_list[i] != FORMAT_UNKNOWN) {
				write_hrm_data(files, opt_directory_name, opt_format_list[i]);
			}
		}
	}

	buf_free(files);
	driver_close();
	return 0;
}
Example #8
0
int write_line(struct Map_info *Map, int type, struct line_pnts *Points)
{
    int i, field, cat, ret;
    static int first_form = 1;
    char *form;
    struct line_cats *Cats;
    struct field_info *Fi;
    dbString html;

    Cats = Vect_new_cats_struct();
    db_init_string(&html);

    cat = var_geti(VAR_CAT);
    if (var_geti(VAR_CAT_MODE) != CAT_MODE_NO && cat > 0 &&
	var_geti(VAR_FIELD) > 0) {
	Vect_cat_set(Cats, var_geti(VAR_FIELD), cat);

	G_debug(2, "write field = %d cat = %d", var_geti(VAR_FIELD),
		var_geti(VAR_CAT));

	if (cat_max_get(var_geti(VAR_FIELD)) < var_geti(VAR_CAT)) {
	    cat_max_set(var_geti(VAR_FIELD), var_geti(VAR_CAT));
	}
    }

    ret = Vect_write_line(Map, type, Points, Cats);

    for (i = 0; i < Vect_get_num_updated_lines(Map); i++)
	G_debug(2, "Updated line: %d", Vect_get_updated_line(Map, i));

    for (i = 0; i < Vect_get_num_updated_nodes(Map); i++)
	G_debug(2, "Updated node: %d", Vect_get_updated_node(Map, i));

    /* Reset category (this automatically resets cat for next not used) */
    var_seti(VAR_FIELD, var_geti(VAR_FIELD));

    if (var_geti(VAR_CAT_MODE) != CAT_MODE_NO && var_geti(VAR_INSERT) &&
	cat > 0) {
	G_debug(2, "Insert new record");
	db_set_string(&html, "<HTML><HEAD><TITLE>");
	db_append_string(&html, _("Form"));
	db_append_string(&html, "</TITLE><BODY>");

	field = var_geti(VAR_FIELD);
	ret = new_record(field, cat);
	if (ret == -1) {
	    return -1;
	}
	else if (ret == 0) {
	    db_append_string(&html, _("New record was created.<BR>"));
	}
	else {			/* record already existed */
	    db_append_string(&html,
			     _("Record for this category already existed.<BR>"));
	}

	/* Open form */
	Fi = Vect_get_field(Map, field);
	if (Fi == NULL) {
	    return -1;
	}
	F_generate(Fi->driver, Fi->database, Fi->table, Fi->key, cat, NULL,
		   NULL, F_EDIT, F_HTML, &form);
	db_append_string(&html, form);
	db_append_string(&html, "</BODY></HTML>");

	/* Note: F_open() must be run first time with closed monitor, otherwise next
	 *        attempt to open driver hangs until form child process is killed */
	if (first_form)
	    driver_close();
	F_clear();
	F_open(_("Attributes"), db_get_string(&html));
	if (first_form) {
	    driver_open();
	    first_form = 0;
	}

	G_free(form);
	db_free_string(&html);

    }

    return 0;
}