equilibrium2-mgmt_main.c

Go to the documentation of this file.
00001 /*
00002  * $Id: equilibrium2-mgmt_main.c 346460 2009-11-14 05:06:47Z ssiano $
00003  *
00004  * This code is provided as is by Juniper Networks SDK Developer Support.
00005  * It is provided with no warranties or guarantees, and Juniper Networks
00006  * will not provide support or maintenance of this code in any fashion.
00007  * The code is provided only to help a developer better understand how
00008  * the SDK can be used.
00009  * 
00010  * Copyright (c) 2008, Juniper Networks, Inc.
00011  * All rights reserved.
00012  */
00013 
00022 /* The Application and This Daemon's Documentation: */
00023 
00218 #include <sync/equilibrium2.h>
00219 #include "equilibrium2-mgmt.h"
00220 
00221 #include <stdlib.h>
00222 #include <jnx/trace.h>
00223 #include <jnx/junos_trace.h>
00224 #include <jnx/junos_init.h>
00225 #include <jnx/pmon.h>
00226 
00227 #include EQUILIBRIUM2_OUT_H
00228 #include EQUILIBRIUM2_SEQUENCE_H
00229 
00230 /*** Constants ***/
00231 
00232 /*** Data Structures ***/
00233 
00234 extern const parse_menu_t master_menu[];
00235 
00236 static junos_pmon_context_t pmon; 
00238 /*** STATIC/INTERNAL Functions ***/
00239 
00245 static void
00246 main_exit (void)
00247 {
00248     server_close();
00249     kcom_close();
00250     config_clear();
00251     junos_pmon_destroy_context(&pmon);
00252 
00253     EQ2_TRACE(EQ2_TRACEFLAG_NORMAL, "%s: Equilibrium2 exit.", __func__);
00254     exit(0);
00255 }
00256 
00264 static void
00265 eq2_sigterm (int signo UNUSED)
00266 {
00267     main_exit();
00268 }
00269 
00280 static int
00281 main_init (evContext ctx)
00282 {
00283     pmon = NULL;
00284     struct timespec interval;
00285     provider_info_origin_description_t desc;
00286 
00287     EQ2_TRACE(EQ2_TRACEFLAG_NORMAL, "%s: Start initializing.", __func__);
00288 
00289     junos_sig_register(SIGTERM, eq2_sigterm);
00290 
00291     provider_info_get_origin_id(&eq2_origin_id);
00292     eq2_provider_id = provider_info_get_provider_id_from_origin_id(
00293             eq2_origin_id, desc);
00294     EQ2_TRACE(EQ2_TRACEFLAG_NORMAL, "%s: Provider ID 0x%08x.", __func__,
00295             eq2_provider_id);
00296 
00297     config_init();
00298 
00299     if (kcom_init(ctx) != KCOM_OK) {
00300         goto error;
00301     }
00302 
00303     if ((pmon = junos_pmon_create_context()) == PMON_CONTEXT_INVALID) {
00304         EQ2_LOG(LOG_ERR, "%s: Initialize health monitoring ERROR!",
00305                 __func__);
00306         goto error;
00307     }
00308     if (junos_pmon_set_event_context(pmon, ctx)) {
00309         EQ2_LOG(LOG_ERR, "%s: Setup health monitoring ERROR!",
00310                 __func__);
00311         goto error;
00312     }
00313     if (junos_pmon_select_backend(pmon, PMON_BACKEND_LOCAL, NULL)) {
00314         EQ2_LOG(LOG_ERR, "%s: Select health monitoring backend ERROR!",
00315                 __func__);
00316         goto error;
00317     }
00318 
00319     interval.tv_sec = PMON_HB_INTERVAL;
00320     interval.tv_nsec = 0;
00321 
00322 #if 0
00323     if (junos_pmon_heartbeat(pmon, &interval, 0)) {
00324         EQ2_LOG(LOG_ERR, "%s: Set health monitoring heartbeat ERROR!",
00325                 __func__);
00326         goto error;
00327     }
00328 #endif
00329 
00330     server_open(ctx);
00331     return 0;
00332 
00333 error:
00334     kcom_close();
00335     config_clear();
00336     if (pmon) {
00337         junos_pmon_destroy_context(&pmon);
00338     }
00339 
00340     return -1;
00341 }
00342 
00343 
00344 /*** GLOBAL/EXTERNAL Functions ***/
00345 
00360 int
00361 main (int argc, char **argv)
00362 {
00363     int ret = 0;
00364     junos_sdk_app_ctx_t app_ctx;
00365     const char *eq2_config[] = { "sync", "equilibrium2", NULL };
00366 
00367     app_ctx = junos_create_app_ctx(argc, argv, DNAME_EQUILIBRIUM2_MGMT,
00368             master_menu, PACKAGE_NAME, SEQUENCE_NUMBER);
00369     if (app_ctx == NULL) {
00370         return -1;
00371     }
00372 
00373     ret = junos_set_app_cb_config_read(app_ctx, eq2_config_read);
00374     if (ret < 0) {
00375         goto error;
00376     }
00377 
00378     ret = junos_set_app_cb_init(app_ctx, main_init);
00379     if (ret < 0) {
00380         goto error;
00381     }
00382 
00383     ret = junos_set_app_cfg_trace_path(app_ctx, eq2_config);
00384     if (ret < 0) {
00385         goto error;
00386     }
00387 
00388     ret = junos_app_init(app_ctx);
00389 
00390 error:
00391     /* should not come here unless daemon exiting or init failed,
00392      * destroy context
00393      */
00394     junos_destroy_app_ctx(app_ctx); 
00395     return ret;
00396 }
00397 

2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:26:58 2010 for SDK Your Net Corporation Equilibrium II: equilibrium2-mgmt 1.0 by Doxygen 1.5.1