Example #1
0
struct log *
log_new(struct attr **attrs)
{
	struct log *ret=g_new0(struct log, 1);
	struct attr *data,*overwrite,*flush_size,*flush_time;

	dbg(1,"enter\n");
	data=attr_search(attrs, NULL, attr_data);
	if (! data)
		return NULL;
	ret->filename=g_strdup(data->u.str);
	overwrite=attr_search(attrs, NULL, attr_overwrite);
	if (overwrite)
		ret->overwrite=overwrite->u.num;
	flush_size=attr_search(attrs, NULL, attr_flush_size);
	if (flush_size)
		ret->flush_size=flush_size->u.num;
	flush_time=attr_search(attrs, NULL, attr_flush_time);
	if (flush_time)
		ret->flush_time=flush_time->u.num;
	if (ret->flush_time) {
		dbg(0,"interval %d\n", ret->flush_time*1000);
		ret->timer=g_timeout_add(ret->flush_time*1000, log_timer, ret);
	}
	expand_filenames(ret);
	log_open(ret);
	gettimeofday(&ret->last_flush, NULL);
	return ret;
}
Example #2
0
static struct map_priv *
map_new_textfile(struct map_methods *meth, struct attr **attrs)
{
	struct map_priv *m;
	struct attr *data=attr_search(attrs, NULL, attr_data);
	struct attr *charset=attr_search(attrs, NULL, attr_charset);
	struct file_wordexp *wexp;
	int len,is_pipe=0;
	char *wdata;
	char **wexp_data;
	if (! data)
		return NULL;
	dbg(1,"map_new_textfile %s\n", data->u.str);	
	wdata=g_strdup_printf(data->u.str);
	len=strlen(wdata);
	if (len && wdata[len-1] == '|') {
		wdata[len-1]='\0';
		is_pipe=1;
	}
	wexp=file_wordexp_new(wdata);
	wexp_data=file_wordexp_get_array(wexp);
	*meth=map_methods_textfile;

	m=g_new0(struct map_priv, 1);
	m->id=++map_id;
	m->filename=g_strdup(wexp_data[0]);
	m->is_pipe=is_pipe;
	dbg(1,"map_new_textfile %s %s\n", m->filename, wdata);
	if (charset) {
		m->charset=g_strdup(charset->u.str);
		meth->charset=m->charset;
	}
	file_wordexp_destroy(wexp);
	return m;
}
Example #3
0
static struct map_priv *
map_new_binfile(struct map_methods *meth, struct attr **attrs)
{
	struct map_priv *m;
	struct attr *data=attr_search(attrs, NULL, attr_data);
	struct attr *check_version;
	struct file_wordexp *wexp;
	char **wexp_data;
	if (! data)
		return NULL;

	wexp=file_wordexp_new(data->u.str);
	wexp_data=file_wordexp_get_array(wexp);
	dbg(1,"map_new_binfile %s\n", data->u.str);	
	*meth=map_methods_binfile;

	m=g_new0(struct map_priv, 1);
	m->id=++map_id;
	m->filename=g_strdup(wexp_data[0]);
	file_wordexp_destroy(wexp);
	check_version=attr_search(attrs, NULL, attr_check_version);
	if (check_version) 
		m->check_version=check_version->u.num;
	if (!map_binfile_open(m)) {
		map_binfile_destroy(m);
		m=NULL;
	}
	return m;
}
Example #4
0
struct cursor *
cursor_new(struct attr *parent, struct attr **attrs)
{
	struct attr *w, *h, *name, *interval, *sequence_range;

	w=attr_search(attrs, NULL, attr_w);
	h=attr_search(attrs, NULL, attr_h);
	if (! w || ! h)
		return NULL;

	struct cursor *this=g_new0(struct cursor,1);
	this->w=w->u.num;
	this->h=h->u.num;
	name=attr_search(attrs, NULL, attr_name);
	if (name)
		this->name=g_strdup(name->u.str);
	else
		this->name=g_strdup("default");
	interval=attr_search(attrs, NULL, attr_interval);
	if (interval)
		this->interval=interval->u.num;
	sequence_range=attr_search(attrs, NULL, attr_sequence_range);
	if (sequence_range) {
		struct range *r=g_new0(struct range,1);
		r->min=sequence_range->u.range.min;
		r->max=sequence_range->u.range.max;
		this->sequence_range=r;
	}
	else {
		this->sequence_range=NULL;
Example #5
0
static struct vehicle_priv *
vehicle_demo_new(struct vehicle_methods
		 *meth, struct callback_list
		 *cbl, struct attr **attrs)
{
	struct vehicle_priv *ret;
	struct attr *interval,*speed,*position_coord_geo;

	dbg(1, "enter\n");
	ret = g_new0(struct vehicle_priv, 1);
	ret->cbl = cbl;
	ret->interval=1000;
	ret->config_speed=40;
	if ((speed=attr_search(attrs, NULL, attr_speed))) {
		ret->config_speed=speed->u.num;
	}
	if ((interval=attr_search(attrs, NULL, attr_interval)))
		ret->interval=interval->u.num;
	if ((position_coord_geo=attr_search(attrs, NULL, attr_position_coord_geo))) {
		ret->geo=*(position_coord_geo->u.coord_geo);
		ret->position_set=1;
		dbg(0,"position_set %f %f\n", ret->geo.lat, ret->geo.lng);
	}
	*meth = vehicle_demo_methods;
	ret->timer_callback=callback_new_1(callback_cast(vehicle_demo_timer), ret);
	ret->timer=event_add_timeout(ret->interval, 1, ret->timer_callback);
	return ret;
}
Example #6
0
File: maps.c Project: PDXostc/navit
struct maps *
maps_new(struct attr *parent, struct attr **attrs)
{
	struct attr *data,**attrs_dup;
	if (!parent) {
		dbg(lvl_error,"No parent\n");
		return NULL;
	}
	if (parent->type != attr_mapset) {
		dbg(lvl_error,"Parent must be mapset\n");
		return NULL;
	}
	dbg(lvl_debug,"enter\n");
	attrs_dup=attr_list_dup(attrs);
	data=attr_search(attrs_dup, NULL, attr_data);
	if (data) {
		struct file_wordexp *wexp=file_wordexp_new(data->u.str);
		int i,count=file_wordexp_get_count(wexp);
		char **array=file_wordexp_get_array(wexp);
		struct attr *name;
		struct attr *name_provided = attr_search(attrs_dup, NULL, attr_name);

		// if no name was provided, fill the name with the location
		if (!name_provided) {
			struct attr name_tmp;
			name_tmp.type = attr_name;
			name_tmp.u.str="NULL";
			attrs_dup=attr_generic_add_attr(attrs_dup, &name_tmp);
			name = attr_search(attrs_dup, NULL, attr_name);
		}

		for (i = 0 ; i < count ; i++) {
			struct attr map;
			g_free(data->u.str);
			data->u.str=g_strdup(array[i]);

			if (!name_provided) {
				g_free(name->u.str);
				name->u.str=g_strdup(array[i]);
			}

			map.type=attr_map;
			map.u.map=map_new(parent, attrs_dup);

			if (map.u.map) {
				mapset_add_attr(parent->u.mapset, &map);
				navit_object_unref(map.u.navit_object);
			}
			
		}
		file_wordexp_destroy(wexp);	
	} else {
		dbg(lvl_error,"no data attribute\n");
	}
	attr_list_free(attrs_dup);
	return NULL;
}
Example #7
0
struct coord *
coord_new_from_attrs(struct attr *parent, struct attr **attrs)
{
	struct attr *x,*y;
	x=attr_search(attrs, NULL, attr_x);
	y=attr_search(attrs, NULL, attr_y);
	if (!x || !y)
		return NULL;
	return coord_new(x->u.num, y->u.num);
}
Example #8
0
static int
vehicle_add_log(struct vehicle *this_, struct log *log,
		struct attr **attrs)
{
	struct attr *type;
	struct callback *cb;
	type = attr_search(attrs, NULL, attr_type);
	if (!type)
		return 1;
	if (!strcmp(type->u.str, "nmea")) {
		cb=callback_new_2(callback_cast(vehicle_log_nmea), this_, log);
	} else if (!strcmp(type->u.str, "gpx")) {
		char *header =
		    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gpx version=\"1.0\" creator=\"Navit http://navit.sourceforge.net\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/0\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n<trk>\n<trkseg>\n";
		char *trailer = "</trkseg>\n</trk>\n</gpx>\n";
		log_set_header(log, header, strlen(header));
		log_set_trailer(log, trailer, strlen(trailer));
		cb=callback_new_2(callback_cast(vehicle_log_gpx), this_, log);
	} else if (!strcmp(type->u.str, "textfile")) {
		char *header = "type=track\n";
		log_set_header(log, header, strlen(header));
		cb=callback_new_2(callback_cast(vehicle_log_textfile), this_, log);
	} else
		return 1;
	callback_list_add(this_->cbl, cb);
	return 0;
}
Example #9
0
struct layout * layout_new(struct attr *parent, struct attr **attrs)
{
	struct layout *l;
	struct color def_color = {COLOR_BACKGROUND_};
	struct attr *name_attr,*color_attr,*order_delta_attr,*font_attr,*day_attr,*night_attr,*active_attr;

	if (! (name_attr=attr_search(attrs, NULL, attr_name)))
		return NULL;
	l = g_new0(struct layout, 1);
	l->func=&layout_func;
	navit_object_ref((struct navit_object *)l);
	l->name = g_strdup(name_attr->u.str);
	if ((font_attr=attr_search(attrs, NULL, attr_font))) {
		l->font = g_strdup(font_attr->u.str);
	}
	if ((day_attr=attr_search(attrs, NULL, attr_daylayout))) {
		l->dayname = g_strdup(day_attr->u.str);
	}
	if ((night_attr=attr_search(attrs, NULL, attr_nightlayout))) {
		l->nightname = g_strdup(night_attr->u.str);
	}
	if ((color_attr=attr_search(attrs, NULL, attr_color)))
		l->color = *color_attr->u.color;
	else
		l->color = def_color;
	if ((order_delta_attr=attr_search(attrs, NULL, attr_order_delta)))
		l->order_delta=order_delta_attr->u.num;
	if ((active_attr=attr_search(attrs, NULL, attr_active)))
		l->active = active_attr->u.num;
	l->navit=parent->u.navit;
	return l;
}
Example #10
0
struct debug *
debug_new(struct attr *parent, struct attr **attrs)
{
	struct attr *name, *level;
	name = attr_search(attrs, NULL, attr_name);
	level = attr_search(attrs, NULL, attr_level);
#ifdef HAVE_SOCKET
	if (!name && !level)
	{
		struct attr *socket_attr=attr_search(attrs, NULL, attr_socket);
		char *p,*s;

		if (!socket_attr)
			return NULL;

		s=g_strdup(socket_attr->u.str);
		p=strchr(s,':');
		if (!p)
		{
			g_free(s);
			return NULL;
		}
		*p++='\0';
		debug_sin.sin_family=AF_INET;
		if (!inet_aton(s, &debug_sin.sin_addr))
		{
			g_free(s);
			return NULL;
		}
		debug_sin.sin_port=ntohs(atoi(p));
		if (debug_socket == -1)
		debug_socket=socket(PF_INET, SOCK_DGRAM, 0);
		g_free(s);
		return (struct debug *)&dummy;
	}
#endif
	if (!name || !level)
		return NULL;

	debug_level_set(name->u.str, level->u.num);

	return (struct debug *) &dummy;
}
Example #11
0
File: file.c Project: albertz/navit
static int
file_request_do(struct file *file, struct attr **options, int connect)
{
	struct attr *attr;
	char *name;

	if (!options)
		return 0;
	attr=attr_search(options, NULL, attr_url);
	if (!attr)
		return 0;
	name=attr->u.str;
	if (!name)
		return 0;
	g_free(file->name);
	file->name = g_strdup(name);
	if (!strncmp(name,"http://",7)) {
		char *host=g_strdup(name+7);
		char *port=strchr(host,':');
		char *path=strchr(name+7,'/');
		char *method="GET";
		char *header=NULL;
		int persistent=0;
		if ((attr=attr_search(options, NULL, attr_http_method)) && attr->u.str)
			method=attr->u.str;
		if ((attr=attr_search(options, NULL, attr_http_header)) && attr->u.str)
			header=attr->u.str;
		if ((attr=attr_search(options, NULL, attr_persistent)))
			persistent=attr->u.num;
		if (path) 
			host[path-name-7]='\0';
		if (port)
			*port++='\0';
		dbg(1,"host=%s path=%s\n",host,path);
		if (connect) 
			file->fd=file_socket_connect(host,port?port:"80");
		file_http_request(file,method,host,path,header,persistent);
		file->special=1;
		g_free(host);
	}
	return 1;
}
Example #12
0
static struct map_priv *
map_new_textfile(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl)
{
    struct map_priv *m;
    struct attr *data=attr_search(attrs, NULL, attr_data);
    struct attr *charset=attr_search(attrs, NULL, attr_charset);
    struct attr *flags=attr_search(attrs, NULL, attr_flags);
    struct attr *no_warn=attr_search(attrs, NULL, attr_no_warning_if_map_file_missing);
    struct file_wordexp *wexp;
    int len,is_pipe=0;
    char *wdata;
    char **wexp_data;
    if (! data)
        return NULL;
    dbg(lvl_debug,"map_new_textfile %s\n", data->u.str);
    wdata=g_strdup(data->u.str);
    len=strlen(wdata);
    if (len && wdata[len-1] == '|') {
        wdata[len-1]='\0';
        is_pipe=1;
    }
    wexp=file_wordexp_new(wdata);
    wexp_data=file_wordexp_get_array(wexp);
    *meth=map_methods_textfile;

    m=g_new0(struct map_priv, 1);
    m->id=++map_id;
    m->filename=g_strdup(wexp_data[0]);
    m->is_pipe=is_pipe;
    m->no_warning_if_map_file_missing=(no_warn!=NULL) && (no_warn->u.num);
    if (flags)
        m->flags=flags->u.num;
    dbg(lvl_debug,"map_new_textfile %s %s\n", m->filename, wdata);
    if (charset) {
        m->charset=g_strdup(charset->u.str);
        meth->charset=m->charset;
    }
    file_wordexp_destroy(wexp);
    g_free(wdata);
    return m;
}
Example #13
0
static void
script_run(struct script *scr)
{
    struct attr *xml_text=attr_search(scr->attrs, NULL, attr_xml_text);
    int error;
    if (!xml_text || !xml_text->u.str) {
        dbg(lvl_error,"no text\n");
        return;
    }
    dbg(lvl_debug,"running '%s'\n",xml_text->u.str);
    command_evaluate_to_void(&scr->parent, xml_text->u.str, &error);
}
Example #14
0
struct layout * layout_new(struct attr *parent, struct attr **attrs)
{
	struct layout *l;
	struct color def_color = {0xffff, 0xefef, 0xb7b7, 0xffff};
	struct attr *name_attr,*color_attr,*order_delta_attr,*font_attr,*day_attr,*night_attr;

	if (! (name_attr=attr_search(attrs, NULL, attr_name)))
		return NULL;
	l = g_new0(struct layout, 1);
	l->name = g_strdup(name_attr->u.str);
	if ((font_attr=attr_search(attrs, NULL, attr_font))) {
		l->font = g_strdup(font_attr->u.str);
	}
	if ((day_attr=attr_search(attrs, NULL, attr_daylayout))) {
		l->dayname = g_strdup(day_attr->u.str);
	}
	if ((night_attr=attr_search(attrs, NULL, attr_nightlayout))) {
		l->nightname = g_strdup(night_attr->u.str);
	}
	if ((color_attr=attr_search(attrs, NULL, attr_color)))
		l->color = *color_attr->u.color;
	else
		l->color = def_color;
	if ((order_delta_attr=attr_search(attrs, NULL, attr_order_delta)))
		l->order_delta=order_delta_attr->u.num;
	return l;
}
Example #15
0
File: file.c Project: albertz/navit
struct file *
file_create(char *name, struct attr **options)
{
	struct stat stat;
	struct file *file= g_new0(struct file,1);
	struct attr *attr;
	int open_flags=O_LARGEFILE|O_BINARY;

	if (options && (attr=attr_search(options, NULL, attr_url))) {
#ifdef HAVE_SOCKET
		file_request_do(file, options, 1);
#endif
	} else {
		if (options && (attr=attr_search(options, NULL, attr_readwrite)) && attr->u.num) {
			open_flags |= O_RDWR;
			if ((attr=attr_search(options, NULL, attr_create)) && attr->u.num)
				open_flags |= O_CREAT;
		} else
			open_flags |= O_RDONLY;
		file->name = g_strdup(name);
		file->fd=open(name, open_flags, 0666);
		if (file->fd == -1) {
			g_free(file);
			return NULL;
		}
		dbg(1,"fd=%d\n", file->fd);
		file->size=lseek(file->fd, 0, SEEK_END);
		dbg(1,"size="LONGLONG_FMT"\n", file->size);
		file->name_id = (long)atom(name);
	}
#ifdef CACHE_SIZE
	if (!options || !(attr=attr_search(options, NULL, attr_cache)) || attr->u.num)
		file->cache=1;
#endif
	dbg_assert(file != NULL);
	return file;
}
Example #16
0
struct vehicleprofile *
vehicleprofile_new(struct attr *parent, struct attr **attrs)
{
	struct vehicleprofile *this_;
	struct attr **attr, *type_attr;
	if (! (type_attr=attr_search(attrs, NULL, attr_name))) {
		return NULL;
	}
	this_=g_new0(struct vehicleprofile, 1);
	this_->attrs=attr_list_dup(attrs);
	this_->roadprofile_hash=g_hash_table_new(NULL, NULL);
	for (attr=attrs;*attr; attr++)
		vehicleprofile_set_attr_do(this_, *attr);
	return this_;
}
Example #17
0
File: log.c Project: Jalakas/navit
struct log *
log_new(struct attr * parent,struct attr **attrs)
{
	struct log *ret=g_new0(struct log, 1);
	struct attr *data,*overwrite,*lazy,*mkdir,*flush_size,*flush_time;
	struct file_wordexp *wexp;
	char *filename, **wexp_data;

	dbg(1,"enter\n");
	ret->func=&log_func;
	navit_object_ref((struct navit_object *)ret);
	data=attr_search(attrs, NULL, attr_data);
	if (! data)
		return NULL;
	filename=data->u.str;
	wexp=file_wordexp_new(filename);
	if (wexp && file_wordexp_get_count(wexp) > 0) {
		wexp_data=file_wordexp_get_array(wexp);
		filename=wexp_data[0];
	}
	if (filename)
		ret->filename=g_strdup(filename);
	if (wexp)
		file_wordexp_destroy(wexp);
	overwrite=attr_search(attrs, NULL, attr_overwrite);
	if (overwrite)
		ret->overwrite=overwrite->u.num;
	lazy=attr_search(attrs, NULL, attr_lazy);
	if (lazy)
		ret->lazy=lazy->u.num;
	mkdir=attr_search(attrs, NULL, attr_mkdir);
	if (mkdir)
		ret->mkdir=mkdir->u.num;
	flush_size=attr_search(attrs, NULL, attr_flush_size);
	if (flush_size)
		ret->flush_size=flush_size->u.num;
	flush_time=attr_search(attrs, NULL, attr_flush_time);
	if (flush_time)
		ret->flush_time=flush_time->u.num;
	if (ret->flush_time) {
		dbg(1,"interval %d\n", ret->flush_time*1000);
		ret->timer_callback=callback_new_1(callback_cast(log_timer), ret);
		ret->timer=event_add_timeout(ret->flush_time*1000, 1, ret->timer_callback);
	}
	expand_filenames(ret);
	if (ret->lazy)
		log_set_last_flush(ret);
	else
		log_open(ret);
	ret->attrs=attr_list_dup(attrs);
	return ret;
}
Example #18
0
/**
 * Creates a new graphics object
 * attr type required
 * @param <>
 * @returns <>
 * @author Martin Schaller (04/2008)
*/
struct graphics * graphics_new(struct attr *parent, struct attr **attrs)
{
	struct graphics *this_;
    	struct attr *type_attr;
	struct graphics_priv * (*graphicstype_new)(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl);

        if (! (type_attr=attr_search(attrs, NULL, attr_type))) {
                return NULL;
        }

	graphicstype_new=plugin_get_graphics_type(type_attr->u.str);
	if (! graphicstype_new)
		return NULL;
	this_=g_new0(struct graphics, 1);
	this_->cbl=callback_list_new();
	this_->priv=(*graphicstype_new)(parent->u.navit, &this_->meth, attrs, this_->cbl);
	this_->attrs=attr_list_dup(attrs);
	return this_;
}
Example #19
0
struct vehicle *
vehicle_new(struct attr **attrs)
{
	struct vehicle *this_;
	struct attr *source;
	struct vehicle_priv *(*vehicletype_new) (struct vehicle_methods *
						 meth,
						 struct callback_list *
						 cbl,
						 struct attr ** attrs);
	char *type, *colon;

	dbg(1, "enter\n");
	source = attr_search(attrs, NULL, attr_source);
	if (!source) {
		dbg(0, "no source\n");
		return NULL;
	}

	type = g_strdup(source->u.str);
	colon = index(type, ':');
	if (colon)
		*colon = '\0';
	dbg(1, "source='%s' type='%s'\n", source->u.str, type);

	vehicletype_new = plugin_get_vehicle_type(type);
	if (!vehicletype_new) {
		dbg(0, "invalid type\n");
		return NULL;
	}
	this_ = g_new0(struct vehicle, 1);
	this_->cbl = callback_list_new();
	this_->priv = vehicletype_new(&this_->meth, this_->cbl, attrs);
	if (!this_->priv) {
		dbg(0, "vehicletype_new failed\n");
		callback_list_destroy(this_->cbl);
		g_free(this_);
		return NULL;
	}
	dbg(1, "leave\n");

	return this_;
}
Example #20
0
static struct vehicle_priv *
vehicle_gpsd_new_gpsd(struct vehicle_methods
			*meth, struct callback_list
			*cbl, struct attr **attrs)
{
	struct vehicle_priv *ret;
	struct attr *source;

	ENTER();
	source = attr_search(attrs, NULL, attr_source);
	ret = g_new0(struct vehicle_priv, 1);
	ret->source = g_strdup(source->u.str);
	ret->cbl = cbl;
	*meth = vehicle_gpsd_methods;
	if (vehicle_gpsd_open(ret))
		return ret;
	gpsd_start_reconnect(priv);
	vehicle_gpsd_destroy(ret);
	return NULL;
}
Example #21
0
struct vehicleprofile *
vehicleprofile_new(struct attr *parent, struct attr **attrs)
{
    struct vehicleprofile *this_;
    struct attr **attr, *type_attr;
    if (! (type_attr=attr_search(attrs, NULL, attr_name))) {
        return NULL;
    }
    this_=g_new0(struct vehicleprofile, 1);
    this_->attrs=attr_list_dup(attrs);
    this_->roadprofile_hash=g_hash_table_new(NULL, NULL);
    this_->length=-1;
    this_->width=-1;
    this_->height=-1;
    this_->weight=-1;
    this_->axle_weight=-1;
    this_->through_traffic_penalty=9000;
    for (attr=attrs; *attr; attr++)
        vehicleprofile_set_attr_do(this_, *attr);
    return this_;
}
Example #22
0
/** @fn static struct vehicle_priv * vehicle_file_new_file(
*                                       struct vehicle_methods *meth,
*                                       struct callback_list   *cbl,
*                                       struct attr            **attrs)
*****************************************************************************
* @b Description: Function called to initialize the plugin
*****************************************************************************
* @param      meth  : ?
* @param      cbl   : ?
* @param      attrs : ?
*****************************************************************************
* @return     pointer on the private data of the plugin
*****************************************************************************
* @remarks private data is allocated by this function (g_new0)
*****************************************************************************
**/
static struct vehicle_priv *
vehicle_file_new_file(struct vehicle_methods
		      *meth, struct callback_list
		      *cbl, struct attr **attrs)
{
	struct vehicle_priv *ret;
	struct attr *source;
	struct attr *time;
	struct attr *on_eof;
	struct attr *baudrate;
	struct attr *checksum_ignore;

	dbg(1, "enter\n");

	source = attr_search(attrs, NULL, attr_source);
	if(source == NULL){
		 dbg(0,"Missing source attribute");
		 return NULL;
    }
	ret = g_new0(struct vehicle_priv, 1);   // allocate and initialize to 0
	ret->fd = -1;
	ret->cbl = cbl;
	ret->source = g_strdup(source->u.str);
	ret->buffer = g_malloc(buffer_size);
	ret->time=1000;
	ret->baudrate=B4800;
	time = attr_search(attrs, NULL, attr_time);
	if (time)
		ret->time=time->u.num;
	baudrate = attr_search(attrs, NULL, attr_baudrate);
	if (baudrate) {
		switch (baudrate->u.num) {
		case 4800:
			ret->baudrate=B4800;
			break;
		case 9600:
			ret->baudrate=B9600;
			break;
		case 19200:
			ret->baudrate=B19200;
			break;
#ifdef B38400
		case 38400:
			ret->baudrate=B38400;
			break;
#endif
#ifdef B57600
		case 57600:
			ret->baudrate=B57600;
			break;
#endif
#ifdef B115200
		case 115200:
			ret->baudrate=B115200;
			break;
#endif
		}
	}
	checksum_ignore = attr_search(attrs, NULL, attr_checksum_ignore);
	if (checksum_ignore)
		ret->checksum_ignore=checksum_ignore->u.num;
	ret->attrs = attrs;
	on_eof = attr_search(attrs, NULL, attr_on_eof);
	if (on_eof && !strcasecmp(on_eof->u.str, "stop"))
		ret->on_eof=1;
	if (on_eof && !strcasecmp(on_eof->u.str, "exit"))
		ret->on_eof=2;
	dbg(0,"on_eof=%d\n", ret->on_eof);
	*meth = vehicle_file_methods;
	ret->cb=callback_new_1(callback_cast(vehicle_file_io), ret);
	ret->cbt=callback_new_1(callback_cast(vehicle_file_enable_watch_timer), ret);
	ret->sat_item.type=type_position_sat;
	ret->sat_item.id_hi=ret->sat_item.id_lo=0;
	ret->sat_item.priv_data=ret;
	ret->sat_item.meth=&vehicle_file_sat_methods;
#ifdef _WIN32
	ret->no_data_count = 0;
#endif

	dbg(1, "vehicle_file_new_file:open\n");
	if (!vehicle_file_open(ret)) {
        dbg(0, "Failed to open '%s'\n", ret->source);
	}

	vehicle_file_enable_watch(ret);
	// vehicle_file_destroy(ret);
	// return NULL;
	dbg(1, "leave\n");
	return ret;
}
Example #23
0
static struct vehicle_priv *
vehicle_wince_new(struct vehicle_methods
		      *meth, struct callback_list
		      *cbl, struct attr **attrs)
{
	struct vehicle_priv *ret;
	struct attr *source;
	struct attr *time;
	struct attr *on_eof;
	struct attr *baudrate;
	struct attr *checksum_ignore;
	struct attr *handle_bluetooth;
	char *cp;

	dbg(1, "enter\n");
	source = attr_search(attrs, NULL, attr_source);
	ret = g_new0(struct vehicle_priv, 1);
	ret->fd = -1;
	ret->cbl = cbl;
	
	ret->file_type = file_type_device;
	cp = strchr(source->u.str,':');
	if (cp)
	{
	    if ( strncmp(source->u.str, "file", 4) == 0 )
	        ret->file_type = file_type_file;
		cp++;
	}
	else
		cp = source->u.str;
	ret->source = g_strdup(cp);
	ret->buffer = g_malloc(buffer_size);
	ret->time=1000;
	ret->baudrate=0;	// do not change the rate if not configured

	time = attr_search(attrs, NULL, attr_time);
	if (time)
		ret->time=time->u.num;
	baudrate = attr_search(attrs, NULL, attr_baudrate);
	if (baudrate) {
		ret->baudrate = baudrate->u.num;
	}
	checksum_ignore = attr_search(attrs, NULL, attr_checksum_ignore);
	if (checksum_ignore)
		ret->checksum_ignore=checksum_ignore->u.num;
	ret->attrs = attrs;
	on_eof = attr_search(attrs, NULL, attr_on_eof);
	if (on_eof && !strcasecmp(on_eof->u.str, "stop"))
		ret->on_eof=1;
	if (on_eof && !strcasecmp(on_eof->u.str, "exit"))
		ret->on_eof=2;
	dbg(0,"on_eof=%d\n", ret->on_eof);
	*meth = vehicle_wince_methods;
	ret->priv_cbl = callback_list_new();
	callback_list_add(ret->priv_cbl, callback_new_1(callback_cast(vehicle_wince_io), ret));
	ret->sat_item.type=type_position_sat;
	ret->sat_item.id_hi=ret->sat_item.id_lo=0;
	ret->sat_item.priv_data=ret;
	ret->sat_item.meth=&vehicle_wince_sat_methods;

    ret->read_buffer = g_malloc(buffer_size);

	handle_bluetooth = attr_search(attrs, NULL, attr_bluetooth);
	if ( handle_bluetooth && handle_bluetooth->u.num == 1 )
		initBth(ret);

	if (vehicle_wince_open(ret)) {
		vehicle_wince_enable_watch(ret);
		return ret;
	}
	dbg(0, "Failed to open '%s'\n", ret->source);
	vehicle_wince_destroy(ret);
	return NULL;
}
Example #24
0
struct vehicle *
vehicle_new(struct attr **attrs)
{
	struct vehicle *v;
	struct attr *name,*update,*follow,*color,*active,*source, *id;
	struct vehicle_priv *(*vehicletype_new) (struct vehicle_methods *
						 meth,
						 struct callback_list *
						 cbl,
						 struct attr ** attrs);
	char *type, *colon;

	dbg(1, "enter\n");
	source = attr_search(attrs, NULL, attr_source);
	if (!source) {
		dbg(0, "no source\n");
		return NULL;
	}

	type = g_strdup(source->u.str);
	colon = index(type, ':');
	if (colon)
		*colon = '\0';
	dbg(1, "source='%s' type='%s'\n", source->u.str, type);

	vehicletype_new = plugin_get_vehicle_type(type);
	if (!vehicletype_new) {
		dbg(0, "invalid type\n");
		return NULL;
	}
	v = g_new0(struct vehicle, 1);
	v->cbl = callback_list_new();
	v->priv = vehicletype_new(&v->meth, v->cbl, attrs);
	if (!v->priv) {
		dbg(0, "vehicletype_new failed\n");
		callback_list_destroy(v->cbl);
		g_free(v);
		return NULL;
	}
	v->update = 1;
	v->follow = 0;
	v->active = 0;
	if ((name=attr_search(attrs, NULL, attr_name)))
		v->name=g_strdup(name->u.str);
	else
		v->name=g_strdup("Noname");

	if ((id=attr_search(attrs, NULL, attr_vehicle_id)))
		v->id=id->u.num;
	if ((update=attr_search(attrs, NULL, attr_update)))
		v->update=update->u.num;
	if ((follow=attr_search(attrs, NULL, attr_follow)))
		v->follow=follow->u.num;
	if ((color=attr_search(attrs, NULL, attr_color))) 
		v->c=*(color->u.color);
	if ((active=attr_search(attrs, NULL, attr_active)) && active->u.num) {
		v->active = 1;
//		navit_set_vehicle(this_, v);
	}

	dbg(1, "leave\n");

	return v;
}