counterd_message.c

Go to the documentation of this file.
00001 /*
00002  * $Id: counterd_message.c 366303 2010-03-05 13:14:01Z taoliu $
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  
00023 #include "counterd_config.h"
00024 #include "counterd_message.h"
00025 #include "counterd_kcom.h"
00026 #include "counterd_logging.h"
00027 
00028 
00029 /*** Constants ***/
00030 
00031 
00032 /*** Data structures: ***/
00033 
00034 
00038 typedef struct msg_data_s {
00039     uint32_t times_viewed;          
00040     char message[MESSAGE_STR_SIZE];  
00041 } msg_data_t;
00042 
00043 
00047 static uint32_t times_viewed = 0;
00048 
00049 
00050 /*** STATIC/INTERNAL Functions ***/
00051 
00052 
00053 /*** GLOBAL/EXTERNAL Functions ***/
00054 
00055 
00070 boolean
00071 reset_message(char * new_message)
00072 {
00073     msg_data_t data;
00074     
00075     INSIST(strlen(new_message) < MESSAGE_STR_SIZE);
00076     
00077     if(counterd_get_data(&data, sizeof(data)) > 0) {
00078         
00079         // There's something in GENCFG
00080         
00081         if(strcmp(data.message, new_message) == 0) {
00082         
00083             // message in GENCFG is the same as new_message
00084             times_viewed = data.times_viewed; // save the times_viewed locally
00085             
00086             ERRMSG(COUNTERD, TRACE_LOG_INFO,
00087                 "%s: Got a value of %d from GENCFG.",
00088                 __func__, times_viewed);
00089             
00090             return FALSE;
00091         }
00092     }
00093     
00094     // set new values to go into storage and add it
00095     
00096     times_viewed = data.times_viewed = 0;
00097     strcpy(data.message, new_message);
00098     
00099     counterd_add_data(&data, sizeof(data));
00100     
00101     ERRMSG(COUNTERD, TRACE_LOG_INFO,
00102         "%s: Did not get any value from GENCFG. Defaulting it to zero.",
00103         __func__);
00104     
00105     return TRUE;
00106 }
00107 
00108 
00114 char *
00115 get_message(void)
00116 {
00117     counter_data_t * data;
00118     msg_data_t msg_data;
00119 
00120     if((data = first_message()) != NULL) {
00121 
00122         // increment message-viewed counter
00123         msg_data.times_viewed = ++times_viewed;
00124         strcpy(msg_data.message, data->message);
00125         
00126         // replace values in storage
00127         counterd_add_data(&msg_data, sizeof(msg_data));
00128         
00129         return data->message;
00130     }
00131     
00132     return NULL;
00133 }
00134 
00135 
00141 uint32_t
00142 get_times_viewed(void)
00143 {
00144     return times_viewed;
00145 }
00146 
00147 

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:53 2010 for SDK Your Net Corporation Counter Example 1.0 by Doxygen 1.5.1