]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/conf-context.c
XTypes: Added support to configuration and option parser.
[libucw.git] / ucw / conf-context.c
index 1584143cb98a24b959dda540935105d2ea084620..050e43baaf47fc218e83f74aaf20479d83d14eeb 100644 (file)
 #include <ucw/conf-internal.h>
 #include <ucw/threads.h>
 
 #include <ucw/conf-internal.h>
 #include <ucw/threads.h>
 
-#ifndef CONFIG_UCW_DEFAULT_CONFIG
-#define CONFIG_UCW_DEFAULT_CONFIG NULL
-#endif
+static struct cf_context cf_default_context;
 
 
-#ifndef CONFIG_UCW_ENV_VAR_CONFIG
-#define CONFIG_UCW_ENV_VAR_CONFIG NULL
-#endif
+static void
+cf_init_context(struct cf_context *cc)
+{
+  cc->enable_journal = 1;
+  clist_init(&cc->conf_entries);
+}
 
 struct cf_context *
 cf_new_context(void)
 {
   struct cf_context *cc = xmalloc_zero(sizeof(*cc));
 
 struct cf_context *
 cf_new_context(void)
 {
   struct cf_context *cc = xmalloc_zero(sizeof(*cc));
-  cc->need_journal = 1;
-  clist_init(&cc->conf_entries);
+  cf_init_context(cc);
   return cc;
 }
 
 void
   return cc;
 }
 
 void
-cf_free_context(struct cf_context *cc)
+cf_delete_context(struct cf_context *cc)
 {
   ASSERT(!cc->is_active);
 {
   ASSERT(!cc->is_active);
+  ASSERT(cc != &cf_default_context);
+  struct cf_context *prev = cf_switch_context(cc);
+  cf_revert();
+  cf_switch_context(prev);
   xfree(cc->parser);
   xfree(cc);
 }
   xfree(cc->parser);
   xfree(cc);
 }
@@ -53,15 +57,16 @@ cf_switch_context(struct cf_context *cc)
   return prev;
 }
 
   return prev;
 }
 
+static void CONSTRUCTOR_WITH_PRIORITY(10100)
+cf_init_default_context(void)
+{
+  cf_init_context(&cf_default_context);
+  ucwlib_thread_context()->cf_context = &cf_default_context;
+  cf_default_context.is_active = 1;
+}
+
 struct cf_context *
 cf_obtain_context(void)
 {
 struct cf_context *
 cf_obtain_context(void)
 {
-  struct ucwlib_context *uc = ucwlib_thread_context();
-  if (unlikely(!uc->cf_context))
-    {
-      struct cf_context *cc = cf_new_context();
-      uc->cf_context = cc;
-      cc->is_active = 1;
-    }
-  return uc->cf_context;
+  return cf_get_context();
 }
 }