hellopics-mgmt_main.c

Go to the documentation of this file.
00001 /*
00002  * $Id: hellopics-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) 2007-2008, Juniper Networks, Inc.
00011  * All rights reserved.
00012  */
00013 
00014 
00022 /* The Application and This Daemon's Documentation: */
00023 
00103 #include <stdlib.h>
00104 #include <string.h>
00105 #include <signal.h>
00106 #include <stdio.h>
00107 #include <sys/types.h>
00108 #include <unistd.h>
00109 #include <isc/eventlib.h>
00110 #include <jnx/aux_types.h>
00111 #include <jnx/bits.h>
00112 #include <jnx/mgmt_sock_pub.h>
00113 #include <jnx/junos_init.h>
00114 #include <jnx/junos_trace.h>
00115 #include "hellopics-mgmt_logging.h"
00116 #include "hellopics-mgmt_config.h"
00117 #include "hellopics-mgmt_conn.h"
00118 #include "hellopics-mgmt_ha.h"
00119 
00120 #include HELLOPICS_OUT_H
00121 #include HELLOPICS_SEQUENCE_H
00122 
00123 /*** Constants ***/
00124 extern volatile boolean is_master;
00125 
00129 #define DNAME_HELLOPICS_MGMT    "hellopics-mgmt"
00130 
00131 /*** Data Structures ***/
00132 
00137 extern const parse_menu_t master_menu[];
00138 
00139 
00140 /*** STATIC/INTERNAL Functions ***/
00141 static void hellopics_mastership_switch(bool master);
00142 evContext present_ctx;
00143 
00153 static int
00154 hellopics_init (evContext ctx)
00155 {
00156     init_connection_stats();
00157     present_ctx = ctx;
00158     init_config();
00159     return init_server(ctx);
00160 }
00161 
00162 
00163 /*** GLOBAL/EXTERNAL Functions ***/
00164 
00165 
00166 
00179 int
00180 main (int argc, char ** argv)
00181 {
00182     const char * hp_config[] = {DDLNAME_SYNC, DDLNAME_SYNC_HELLOPICS, NULL};
00183     int ret = 0;
00184     junos_sdk_app_ctx_t ctx;
00185 
00186     /* Create an application context */
00187     ctx = junos_create_app_ctx(argc, argv, DNAME_HELLOPICS_MGMT,
00188                                master_menu, PACKAGE_NAME, SEQUENCE_NUMBER);
00189     if (ctx == NULL) {
00190          return -1;
00191     }
00192 
00193     /* Set config read call back */
00194     if ((ret = junos_set_app_cb_config_read(ctx, hellopics_config_read))) {
00195         goto cleanup;
00196     }
00197 
00198     /* Set init call back */
00199     if ((ret = junos_set_app_cb_init(ctx, hellopics_init))) {
00200         goto cleanup;
00201     }
00202 
00203     /* set trace options DDL path */
00204     ret = junos_set_app_cfg_trace_path(ctx, hp_config);
00205     if (ret < 0) {
00206         goto cleanup;
00207     }
00208 
00209     if ((ret = junos_set_app_cb_mastership_switch(ctx,
00210                     hellopics_mastership_switch))) {
00211         goto cleanup;
00212     }
00213     /* Calling junos_app_init */
00214     ret = junos_app_init(ctx);
00215 
00216 cleanup:
00217         if (ret != 0)
00218         LOG(LOG_ERR, "%s: Clean up before the exit ", __func__);
00219 
00220     /* Destroying context if daemon init/exit failed */
00221     junos_destroy_app_ctx(ctx);
00222     return ret;
00223 }
00233 static void
00234 hellopics_mastership_switch(bool master __unused)
00235 {
00236    LOG(LOG_INFO, "%s: Switching the daemon mastership", __func__);
00237    kill(getpid(),SIGTERM);
00238 }

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 Hellopics Example: hellopics-mgmt 1.0 by Doxygen 1.5.1