summaryrefslogtreecommitdiff
path: root/navit
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2013-05-26 08:44:02 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2013-05-26 08:44:02 +0000
commit1298062f2e9484e1ee20e1ec9717e562409120b2 (patch)
treee9b601f8ca687d5d592e15a9a8ae3d02da47c080 /navit
parent4acd82ad52253a31987d5e1342b521f44b96b1ac (diff)
downloadnavit-1298062f2e9484e1ee20e1ec9717e562409120b2.tar.gz
Fix:Core:Coding standard and converted speech to new scheme
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@5507 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit')
-rw-r--r--navit/attr.h1
-rw-r--r--navit/speech.c37
-rw-r--r--navit/xmlconfig.c13
-rw-r--r--navit/xmlconfig.h5
4 files changed, 43 insertions, 13 deletions
diff --git a/navit/attr.h b/navit/attr.h
index 0c12ff084..870a8fa6f 100644
--- a/navit/attr.h
+++ b/navit/attr.h
@@ -106,6 +106,7 @@ enum attr_position_valid {
#define ATTR_IS_COORD(x) ((x) >= attr_type_coord_begin && (x) <= attr_type_coord_end)
#define ATTR_IS_GROUP(x) ((x) >= attr_type_group_begin && (x) <= attr_type_group_end)
+#define ATTR_INT(x,y) ((struct attr){attr_##x,{(char *)(y)}})
#define ATTR_DEF_STR(x,y) (&(struct attr){attr_##x,{y}})
#define ATTR_DEF_INT(x,y) (&(struct attr){attr_##x,{(char *)(y)}})
#define ATTR_DEF_ITEMS(x,...) (&(struct attr){attr_##x,{(char *)((enum item_type[]){__VA_ARGS__ , type_none})}})
diff --git a/navit/speech.c b/navit/speech.c
index 1dbe40535..8b03f3c4b 100644
--- a/navit/speech.c
+++ b/navit/speech.c
@@ -23,11 +23,12 @@
#include "item.h"
#include "speech.h"
#include "plugin.h"
+#include "xmlconfig.h"
struct speech {
+ NAVIT_OBJECT;
struct speech_priv *priv;
struct speech_methods meth;
- struct attr **attrs;
};
@@ -50,14 +51,12 @@ speech_new(struct attr *parent, struct attr **attrs)
dbg(0,"wrong type '%s'\n", attr->u.str);
return NULL;
}
- this_=g_new0(struct speech, 1);
- this_->priv=speech_new(&this_->meth, attrs, parent);
- this_->attrs=attr_list_dup(attrs);
+ this_=(struct speech *)navit_object_new(attrs, &speech_func, sizeof(struct speech));
+ this_->priv=speech_new(&this_->meth, this_->attrs, parent);
dbg(1, "say=%p\n", this_->meth.say);
dbg(1,"priv=%p\n", this_->priv);
if (! this_->priv) {
- attr_list_free(this_->attrs);
- g_free(this_);
+ speech_destroy(this_);
return NULL;
}
dbg(1,"return %p\n", this_);
@@ -68,9 +67,9 @@ speech_new(struct attr *parent, struct attr **attrs)
void
speech_destroy(struct speech *this_)
{
- this_->meth.destroy(this_->priv);
- attr_list_free(this_->attrs);
- g_free(this_);
+ if (this_->priv)
+ this_->meth.destroy(this_->priv);
+ navit_object_destroy((struct navit_object *)this_);
}
int
@@ -80,8 +79,9 @@ speech_say(struct speech *this_, const char *text)
return (this_->meth.say)(this_->priv, text);
}
+struct attr active=ATTR_INT(active, 1);
struct attr *speech_default_attrs[]={
- ATTR_DEF_INT(active, 1),
+ &active,
NULL,
};
@@ -146,3 +146,20 @@ speech_set_attr(struct speech *this_, struct attr *attr)
//callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
return 1;
}
+
+struct object_func speech_func = {
+ attr_speech,
+ (object_func_new)speech_new,
+ (object_func_get_attr)speech_get_attr,
+ (object_func_iter_new)navit_object_attr_iter_new,
+ (object_func_iter_destroy)navit_object_attr_iter_destroy,
+ (object_func_set_attr)speech_set_attr,
+ (object_func_add_attr)navit_object_add_attr,
+ (object_func_remove_attr)navit_object_remove_attr,
+ (object_func_init)NULL,
+ (object_func_destroy)speech_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
+};
+
diff --git a/navit/xmlconfig.c b/navit/xmlconfig.c
index f8a01e507..a4fd2e5bf 100644
--- a/navit/xmlconfig.c
+++ b/navit/xmlconfig.c
@@ -273,7 +273,6 @@ static struct object_func object_funcs[] = {
{ attr_polygon, NEW(polygon_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
{ attr_polyline, NEW(polyline_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
{ attr_route, NEW(route_new), GET(route_get_attr), NULL, NULL, SET(route_set_attr), ADD(route_add_attr), REMOVE(route_remove_attr)},
- { attr_speech, NEW(speech_new), GET(speech_get_attr), NULL, NULL, SET(speech_set_attr)},
{ attr_text, NEW(text_new)},
};
@@ -308,6 +307,8 @@ object_func_lookup(enum attr_type type)
return &osd_func;
case attr_trackingo:
return &tracking_func;
+ case attr_speech:
+ return &speech_func;
case attr_vehicle:
return &vehicle_func;
case attr_vehicleprofile:
@@ -1280,6 +1281,16 @@ navit_object_set_methods(void *in, int in_size, void *out, int out_size)
}
struct navit_object *
+navit_object_new(struct attr **attrs, struct object_func *func, int size)
+{
+ struct navit_object *ret=g_malloc0(size);
+ ret->func=func;
+ ret->attrs=attr_list_dup(attrs);
+ navit_object_ref(ret);
+ return ret;
+}
+
+struct navit_object *
navit_object_ref(struct navit_object *obj)
{
obj->refcount++;
diff --git a/navit/xmlconfig.h b/navit/xmlconfig.h
index a2b6632ca..3f2ff3436 100644
--- a/navit/xmlconfig.h
+++ b/navit/xmlconfig.h
@@ -54,9 +54,9 @@ struct object_func {
void *(*unref)(void *);
};
-extern struct object_func map_func, mapset_func, navit_func, osd_func, tracking_func, vehicle_func, maps_func, layout_func, roadprofile_func, vehicleprofile_func, layer_func, config_func, profile_option_func, script_func, log_func;
+extern struct object_func map_func, mapset_func, navit_func, osd_func, tracking_func, vehicle_func, maps_func, layout_func, roadprofile_func, vehicleprofile_func, layer_func, config_func, profile_option_func, script_func, log_func, speech_func;
-#define HAS_OBJECT_FUNC(x) ((x) == attr_map || (x) == attr_mapset || (x) == attr_navit || (x) == attr_osd || (x) == attr_trackingo || (x) == attr_vehicle || (x) == attr_maps || (x) == attr_layout || (x) == attr_roadprofile || (x) == attr_vehicleprofile || (x) == attr_layer || (x) == attr_config || (x) == attr_profile_option || (x) == attr_script || (x) == attr_log)
+#define HAS_OBJECT_FUNC(x) ((x) == attr_map || (x) == attr_mapset || (x) == attr_navit || (x) == attr_osd || (x) == attr_trackingo || (x) == attr_vehicle || (x) == attr_maps || (x) == attr_layout || (x) == attr_roadprofile || (x) == attr_vehicleprofile || (x) == attr_layer || (x) == attr_config || (x) == attr_profile_option || (x) == attr_script || (x) == attr_log || (x) == attr_speech)
#define NAVIT_OBJECT struct object_func *func; int refcount; struct attr **attrs;
struct navit_object {
@@ -64,6 +64,7 @@ struct navit_object {
};
int navit_object_set_methods(void *in, int in_size, void *out, int out_size);
+struct navit_object *navit_object_new(struct attr **attrs, struct object_func *func, int size);
struct navit_object *navit_object_ref(struct navit_object *obj);
void navit_object_unref(struct navit_object *obj);
struct attr_iter * navit_object_attr_iter_new(void);