diff options
author | Thibaut Mattern <thibaut.mattern@gmail.com> | 2007-04-06 15:28:37 +0200 |
---|---|---|
committer | Thibaut Mattern <thibaut.mattern@gmail.com> | 2007-04-06 15:28:37 +0200 |
commit | 42cbd632976d2c9d5293ad03418dce3c7db2797d (patch) | |
tree | afa4457113d404226892fcdb9c7d1d6f413f9acf /src/xine-engine | |
parent | 90ec5563d6d3ce1abd5fc52d4aee1b0ecf6c7516 (diff) | |
download | xine-lib-42cbd632976d2c9d5293ad03418dce3c7db2797d.tar.gz xine-lib-42cbd632976d2c9d5293ad03418dce3c7db2797d.tar.bz2 |
- Moved base64 stuff to xine-utils.
- Added config entry serialization.
- Added serialized config entries to the plugin cache.
--HG--
rename : src/input/base64.c => src/xine-utils/base64.c
rename : src/input/base64.h => src/xine-utils/base64.h
Diffstat (limited to 'src/xine-engine')
-rw-r--r-- | src/xine-engine/configfile.c | 136 | ||||
-rw-r--r-- | src/xine-engine/configfile.h | 15 | ||||
-rw-r--r-- | src/xine-engine/load_plugins.c | 45 |
3 files changed, 180 insertions, 16 deletions
diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index c7cf30968..fce6e4a30 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -1210,6 +1210,139 @@ static void config_unset_new_entry_callback (config_values_t *this) { pthread_mutex_unlock(&this->config_lock); } +static void config_register_entry (config_values_t *this, cfg_entry_t* entry) { + /* FIXME: TODO */ +} + +static int put_int(uint8_t *buffer, int pos, int value) { + int32_t value_int32 = (int32_t)value; + + buffer[pos] = value_int32 & 0xFF; + buffer[pos + 1] = (value_int32 >> 8) & 0xFF; + buffer[pos + 2] = (value_int32 >> 16) & 0xFF; + buffer[pos + 3] = (value_int32 >> 24) & 0xFF; + + return 4; +} + +static int put_string(uint8_t *buffer, int pos, const char *value, int value_len) { + pos += put_int(buffer, pos, value_len); + memcpy(&buffer[pos], value, value_len); + + return 4 + value_len; +} + +static unsigned char* config_serialize_entry (config_values_t *this, const char *key) { + unsigned char *output = NULL; + cfg_entry_t *entry, *prev; + + pthread_mutex_lock(&this->config_lock); + config_lookup_entry_int(this, key, &entry, &prev); + + if (entry) { + /* now serialize this stuff + fields to serialize : + int type; + int range_min; + int range_max; + int exp_level; + char *key; + char *str_default; + char *description; + char *help; + char **enum_values; + */ + + int key_len = 0; + int str_default_len = 0; + int description_len = 0; + int help_len = 0; + + if (entry->key) + key_len = strlen(entry->key); + if (entry->str_default) + str_default_len = strlen(entry->str_default); + if (entry->description) + description_len = strlen(entry->description); + if (entry->help) + help_len = strlen(entry->help); + + // integers + // value: 4 bytes + unsigned long total_len = 4 * sizeof(int32_t); + + // strings (size + char buffer) + // length: 4 bytes + // buffer: length bytes + total_len += sizeof(int32_t) + key_len; + total_len += sizeof(int32_t) + str_default_len; + total_len += sizeof(int32_t) + description_len; + total_len += sizeof(int32_t) + help_len; + + /* enum values... */ + // value count: 4 bytes + // for each value: + // length: 4 bytes + // buffer: length bytes + int value_count = 0; + int value_len[10]; + total_len += sizeof(int32_t); /* value count */ + + char **cur_value = entry->enum_values; + if (cur_value) { + while (*cur_value && (value_count < (sizeof(value_len) / sizeof(int) ))) { + value_len[value_count] = strlen(*cur_value); + total_len += sizeof(int32_t) + value_len[value_count]; + value_count++; + cur_value++; + } + } + + /* Now we have the length needed to serialize the entry and the length of each string */ + uint8_t *buffer = malloc (total_len); + if (!buffer) return NULL; + + /* Let's go */ + int pos = 0; + + // the integers + pos += put_int(buffer, pos, entry->type); + pos += put_int(buffer, pos, entry->range_min); + pos += put_int(buffer, pos, entry->range_max); + pos += put_int(buffer, pos, entry->exp_level); + + // the strings + pos += put_string(buffer, pos, entry->key, key_len); + pos += put_string(buffer, pos, entry->str_default, str_default_len); + pos += put_string(buffer, pos, entry->description, description_len); + pos += put_string(buffer, pos, entry->help, help_len); + + // the enum stuff + pos += put_int(buffer, pos, value_count); + cur_value = entry->enum_values; + + int i; + for (i = 0; i < value_count; i++) { + pos += put_string(buffer, pos, *cur_value, value_len[i]); + cur_value++; + } + + // and now the output encoding + unsigned long output_len; + output = base64_encode (buffer, total_len, &output_len); + + free(buffer); + } + pthread_mutex_unlock(&this->config_lock); + + return output; +} + +static cfg_entry_t* config_deserialize_entry (config_values_t *this, const char *value) { + /* FIXME: TODO */ + return NULL; +} + config_values_t *_x_config_init (void) { #ifdef HAVE_IRIXAL @@ -1249,6 +1382,9 @@ config_values_t *_x_config_init (void) { this->dispose = config_dispose; this->set_new_entry_callback = config_set_new_entry_callback; this->unset_new_entry_callback = config_unset_new_entry_callback; + this->register_entry = config_register_entry; + this->serialize_entry = config_serialize_entry; + this->deserialize_entry = config_deserialize_entry; return this; } diff --git a/src/xine-engine/configfile.h b/src/xine-engine/configfile.h index e98138fa3..e1416432b 100644 --- a/src/xine-engine/configfile.h +++ b/src/xine-engine/configfile.h @@ -157,6 +157,8 @@ struct config_values_s { xine_config_cb_t changed_cb, void *cb_data); + void (*register_entry) (config_values_t *self, cfg_entry_t* entry); + /* convenience function to update range, enum, num and bool values */ void (*update_num) (config_values_t *self, const char *key, int value); @@ -196,6 +198,19 @@ struct config_values_s { void (*unset_new_entry_callback) (config_values_t *self); /* + * serialize a config entry. + * return a base64 null terminated string. + */ + char* (*serialize_entry) (config_values_t *self, const char *key); + + /* + * deserialize a config entry. + * value is a base 64 encoded string + */ + cfg_entry_t* (*deserialize_entry) (config_values_t *self, const char *value); + + + /* * config values are stored here: */ cfg_entry_t *first, *last, *cur; diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index f4be27587..b2d2f1d9d 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -701,15 +701,12 @@ static inline int _plugin_info_equal(const plugin_info_t *a, */ static void _new_entry_cb (void *user_data, xine_cfg_entry_t *entry) { plugin_node_t *node = (plugin_node_t *)user_data; - /* - printf("_new_entry_cb: key %s, plugin id: %s\n", entry->key, node->info->id); - */ + if (!node->config_entry_list) { node->config_entry_list = xine_list_new(); } xine_list_push_back(node->config_entry_list, (void *)entry->key); - } static int _load_plugin_class(xine_t *this, @@ -857,7 +854,7 @@ static void load_required_plugins(xine_t *this) { /* * save plugin list information to file (cached catalog) */ -static void save_plugin_list(FILE *fp, xine_sarray_t *list) { +static void save_plugin_list(xine_t *this, FILE *fp, xine_sarray_t *list) { const plugin_node_t *node; const plugin_file_t *file; @@ -867,7 +864,6 @@ static void save_plugin_list(FILE *fp, xine_sarray_t *list) { const vo_info_t *vo_info; const ao_info_t *ao_info; const post_info_t *post_info; - int i; int list_id = 0; int list_size; @@ -884,9 +880,9 @@ static void save_plugin_list(FILE *fp, xine_sarray_t *list) { fprintf(fp, "api=%d\n", node->info->API ); fprintf(fp, "id=%s\n", node->info->id ); fprintf(fp, "version=%lu\n", (unsigned long) node->info->version ); - + switch (node->info->type & PLUGIN_TYPE_MASK){ - + case PLUGIN_VIDEO_OUT: vo_info = node->info->special_info; fprintf(fp, "visual_type=%d\n", vo_info->visual_type ); @@ -914,7 +910,7 @@ static void save_plugin_list(FILE *fp, xine_sarray_t *list) { demuxer_info = node->info->special_info; fprintf(fp, "demuxer_priority=%d\n", demuxer_info->priority); break; - + case PLUGIN_INPUT: input_info = node->info->special_info; fprintf(fp, "input_priority=%d\n", input_info->priority); @@ -922,10 +918,27 @@ static void save_plugin_list(FILE *fp, xine_sarray_t *list) { case PLUGIN_POST: post_info = node->info->special_info; - fprintf(fp, "post_type=%lu\n", (unsigned long)post_info->type); - break; - } - + fprintf(fp, "post_type=%lu\n", (unsigned long)post_info->type); + break; + } + + if (node->config_entry_list) + { + xine_list_iterator_t ite = xine_list_front(node->config_entry_list); + while (ite) { + char *key = xine_list_get_value(node->config_entry_list, ite); + + /* now get the representation of the config key */ + char *key_value = this->config->serialize_entry(this->config, key); + + printf(" config key: %s, serialization: %d bytes\n", key, strlen(key_value)); + fprintf(fp, "config_key=%s\n", key_value); + + free (key_value); + ite = xine_list_next(node->config_entry_list, ite); + } + } + fprintf(fp, "\n"); list_id++; } @@ -1120,7 +1133,7 @@ static void save_catalog (xine_t *this) { fprintf(fp, "cache_catalog_version=%d\n\n", CACHE_CATALOG_VERSION); for (i = 0; i < PLUGIN_TYPE_MAX; i++) { - save_plugin_list (fp, this->plugin_catalog->plugin_lists[i]); + save_plugin_list (this, fp, this->plugin_catalog->plugin_lists[i]); } fclose(fp); } @@ -1206,9 +1219,9 @@ void _x_scan_plugins (xine_t *this) { free(pluginpath); free(homedir); - save_catalog (this); - load_required_plugins (this); + + save_catalog (this); map_decoders (this); } |