Conversation
|
I am confused by the usage of ":" and "=", is there a difference? |
They're equivalent, I just used the convention the library follows when writing to file itself, which is to use the ":" for objects, and the "=" for scalars/arrays/lists. |
|
@lminiero, Do you still plan merge this code? Should I use new format for my plugin configs or better use old format? |
|
@RSATom definitely planning to merge soon: I was waiting for feedback before doing that, though, as I haven't received any so far. Since you're working on a plugin, your feedback would indeed help make that process faster: in case, please let me know if by playing with this you encounter anything that needs fixing. |
|
I'll align to master later today, as I see there are a couple of conflicts. |
|
Thanks, I'll try to use it and write feedback if meet any issue. |
|
@lminiero, does it miss lists support, or it's intended? |
|
Lists are there, they're called |
|
ah... ok, thank you. |
|
To be precise, we support both arrays and lists when parsing, but when saving to file ourselves we always use list as we don't know if all the items will be of the same time (especially if it's objects). |
|
good point |
|
I've implemented some basic config support in my plugin. It looks like new implementation is well enough for my case. But tbh, my config is very simple atm. Just list of sources... |
|
Merging, as we'll need this for the upcoming Unified Plan work. |
This pull request is a new effort related to the discussion in this post on the Google group. While I started working on YAML as a configuration file format and actually got quite far (some of the work I brought on here, as a matter of fact), I eventually ditched that effort, as I found the format too limiting and confusing for our needs, and I personally found the libyaml library too much of a pain. Some more research later, I found libconfig, a more reasonable format (more in line with what I needed) and a library API much easier to use.
The new configuration format looks like this:
This pull request adds support for a new type of configuration files that use the libconfig format, which in Janus have the
.jcfgextension, to avoid confusion with the existing INI.cfgfiles. As with the previous YAML effort, INI files are still supported, but they're not in the repo anymore, and have been replaced with the counterpart: core and plugins all try and load the.jcfgversion by default, and fallback to.cfgif they can't find it. This means you can keep on using your existing configuration files, although you're encouraged to convert them sooner or later.To make the conversion easier, there's a new tool called
janus-cfgconv. The syntax is very simple:where
sourcepoints to an existing configuration file, and destination to a new file. You can use this tool to convertcfgtojcfgand viceversa: of course, in case thejcfguses constructs the INI format doesn't support (e.g., arrays or lists), then that information will be lost in the process.It's also worth noting that AudioBridge, VideoRoom and TextRoom now don't use plain room IDs as the name of the category anymore, but they need to be prefixed by
room-(e.g.,1234would becomeroom-1234): this is needed because in libconfig setting names can only start with a letter or an asterisk. This means that, when converting, the tool will always add those prefixes for you, in case the setting name is a number. That said, obviously existing INI files will work as before, so whether you add theroom-prefix or not it will still work: this means that a[1234]room category is equivalent to[room-1234], although the latter is preferred since it will be what we'll use internally from now on.Planning to merge soon, so feedback welcome.
C API changes
This section is only relevant if you're a developer working on Janus internally, e.g., on your own plugin. Feel free to ignore all this if you're not doing that.
As I was saying, this effort incorporates some of the changes I made to support YAML in #1116. Specifically, all the refactoring of the
janus_configC API is exactly the same as the one I made there, which means that if you were using our config files in your custom plugin code, you'll have to make some changes to use it now, even if you decide to stick to INI. It's not a lot of changes, but the pattern is different, and the API is now much clearer, more explicit, and with less implicit assumptions. In fact, the old config API did a lot of assumptions, and masqued several things behind the curtains. This made it quite constrained, and proved unusable for these new concepts, like subobjects or arrays. The new API is much cleaner, and is inspired from the Jansson API. For instance, to add something to a config:Lookup is cleaner as well, and so is the removal of nodes from the object.
To understand which changes to make in your code to do all that, it's probably much easier to just look at the diffs for the plugins. Anyway, I'll try to summarize the main changes here:
Items, categories and arrays are really all the same thing, internally, but they're identified by a new type enumerator. Typically, an item will have name and, optionally, value; objects and arrays will have a name and a list of subobjects. Each of these subobjects can be another item, category or array, which means you're free to indent and structure your config files the way you like. Since it's all GList based, this means you're also free to just crawl the config object manually yourself, if you like, starting from the root
janus_configobject which has alistof elements.A common way of getting config values was
janus_config_get_item_drilldown, which is no more. I mean, you can usejanus_config_searchif you want, that has variable arguments that act as a "path" to the element you want to retrieve (e.g., parent->parent->item), but now it's usually best and more efficient to first pick the category you're interested in (as a cache), and then get the items that belongs to it, especially when you're getting many items from the same category (e.g., "general") in sequence. For both operations you can usejanus_config_get, although for categories you might want to usejanus_config_get_createinstead, as that will create the category for you if it doesn't exist (possibly better, especially if you plan to then save the configuration file). Getting an element requires the type you're expecting, and the parent to get it from: ifNULLyou're getting from the root. This means that you'd change your code like this:janus_config_add_categoryandjanus_config_add_item, now you first create the element you need (janus_config_item_createfor items,janus_config_category_createfor categories andjanus_config_array_createfor arrays), and then you add it to the config withjanus_config_add. Asjanus_config_get, this method expects a parent element to add this to, e.g., if you're adding to a category rather than to the root itself. Of course, for categories and arrays you can also just usejanus_config_get_createas shown before, which returns the existing category/array if it exists and creates it for you if it doesn't. This means that you'd change your code like this:janus_config_remove, which expects the name of the element to remove. You also specify the parent to remove it from: again, if NULL, this removes it from the root. If removing a category/array, all the elements contained in it are destroyed too. A simple example on how you now remove a category from the root:Summary
So, as you can see, very few changes needed probably:
janus_config_get_item_drilldowncalls tojanus_config_get_createfor category plus multiplejanus_config_getcalls (enough for when you're only reading config files);janus_config_add_categoryplus multiplejanus_config_add_itemcalls, tojanus_config_get_createfor category and multiplejanus_config_item_create+janus_config_addfor items (only needed when writing to a config file);janus_config_remove_categorytojanus_config_remove(with updated signature; again, only needed when writing to a config file)).