uniautogen.cc

00001 /*
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  * 
00005  * A UniConf moniker that uses an .ini file to look up which moniker it
00006  * should use to find the config file/subtree for a particular application.
00007  */
00008 #include "uniconfroot.h"
00009 #include "unisubtreegen.h"
00010 #include "wvlinkerhack.h"
00011 
00012 WV_LINK(UniAutoGen);
00013 
00014 
00021 WvString uniautogen_moniker("default:ini:/etc/uniconf.conf");
00022 
00023 /*
00024  * A moniker for finding the "right" config generator for a particular
00025  * application, given the application name.
00026  * 
00027  * For example, for moniker "auto:org/gnome/Nautilus", we would:
00028  * 
00029  *  - open /etc/uniconf.conf.
00030  *  - look for org/gnome/Nautilus in there.
00031  *    - if it exists, use that value as the config moniker, and return.
00032  *  - else, look for org/gnome
00033  *    - if it exists, go get that config moniker,  take the subtree 
00034  *       "Nautilus" from there, and return.
00035  *  - else, look for org
00036  *    - if it exists, go get that config moniker,  take the subtree 
00037  *       "gnome/Nautilus" from there, and return.
00038  *  - else, look for /
00039  *    - if it exists, go get that config moniker,  take the subtree 
00040  *       "org/gnome/Nautilus" from there, and return.
00041  *  - else, return a null: generator.
00042  */
00043 static IUniConfGen *creator(WvStringParm s)
00044 {
00045     UniConfRoot cfg(uniautogen_moniker);
00046     const UniConfKey appname(s);
00047     
00048     for (int i = appname.numsegments(); i >= 0; i--)
00049     {
00050         UniConfKey prefix(appname.first(i)), suffix(appname.removefirst(i));
00051 
00052         if (!!cfg.xget(prefix))
00053         {
00054             return new UniSubtreeGen(wvcreate<IUniConfGen>(cfg.xget(prefix)),
00055                                      suffix);
00056         }
00057     }
00058     
00059     return wvcreate<IUniConfGen>("null:");
00060 }
00061 
00062 
00063 static WvMoniker<IUniConfGen> autoreg("auto", creator);

Generated on Thu Jan 24 16:50:54 2008 for WvStreams by  doxygen 1.5.4