• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

I_RecCore.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   Public RecCore declarations
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 #ifndef _I_REC_CORE_H_
00025 #define _I_REC_CORE_H_
00026 
00027 #include "Diags.h"
00028 
00029 #include "I_RecDefs.h"
00030 #include "I_RecAlarms.h"
00031 #include "I_RecSignals.h"
00032 #include "I_RecEvents.h"
00033 
00034 
00035 //-------------------------------------------------------------------------
00036 // Diagnostic Output
00037 //-------------------------------------------------------------------------
00038 int RecSetDiags(Diags * diags);
00039 
00040 //-------------------------------------------------------------------------
00041 // Config File Parsing
00042 //-------------------------------------------------------------------------
00043 typedef void (*RecConfigEntryCallback)(RecT rec_type, RecDataT data_type, const char * name, const char * value, bool inc_version);
00044 
00045 void RecConfigFileInit(void);
00046 int RecConfigFileParse(const char * path, RecConfigEntryCallback handler, bool inc_version);
00047 
00048 // Return a copy of the system's local state directory, taking proxy.config.local_state_dir into account. The
00049 // caller MUST release the result with ats_free().
00050 char * RecConfigReadRuntimeDir();
00051 
00052 // Return a copy of the system's snapshot directory, taking proxy.config.snapshot_dir into account. The caller
00053 // MUST release the result with ats_free().
00054 char * RecConfigReadSnapshotDir();
00055 
00056 // Return a copy of the system's log directory, taking proxy.config.log.logfile_dir into account. The caller
00057 // MUST release the result with ats_free().
00058 char * RecConfigReadLogDir();
00059 
00060 // Return a copy of the system's bin directory, taking proxy.config.bin_path into account. The caller MUST
00061 // release the result with ats_free().
00062 char * RecConfigReadBinDir();
00063 
00064 // Return a copy of a configuration file that is relative to sysconfdir. The relative path to the configuration
00065 // file is specified in the configuration variable named by "file_variable". If the configuration variable has no
00066 // value, NULL is returned. The caller MUST release the result with ats_free().
00067 char * RecConfigReadConfigPath(const char * file_variable, const char * default_value = NULL);
00068 
00069 // This is the same as RecConfigReadConfigPath, except it makes the paths relative to $PREFIX.
00070 char * RecConfigReadPrefixPath(const char * file_variable, const char * default_value = NULL);
00071 
00072 // Return a copy of the persistent stats file. This is $RUNTIMEDIR/records.snap.
00073 // The caller MUST release the result with ats_free().
00074 char * RecConfigReadPersistentStatsPath();
00075 
00076 // Test whether the named configuration value is overridden by an environment variable. Return either
00077 // the overridden value, or the original value. Caller MUST NOT free the result.
00078 const char * RecConfigOverrideFromEnvironment(const char * name, const char * value);
00079 
00080 //-------------------------------------------------------------------------
00081 // Stat Registration
00082 //-------------------------------------------------------------------------
00083 int _RecRegisterStatInt(RecT rec_type, const char *name, RecInt data_default, RecPersistT persist_type);
00084 #define RecRegisterStatInt(rec_type, name, data_default, persist_type) _RecRegisterStatInt((rec_type), (name), (data_default), REC_PERSISTENCE_TYPE(persist_type))
00085 
00086 int _RecRegisterStatFloat(RecT rec_type, const char *name, RecFloat data_default, RecPersistT persist_type);
00087 #define RecRegisterStatFloat(rec_type, name, data_default, persist_type) _RecRegisterStatFloat((rec_type), (name), (data_default), REC_PERSISTENCE_TYPE(persist_type))
00088 
00089 int _RecRegisterStatString(RecT rec_type, const char *name, RecString data_default, RecPersistT persist_type);
00090 #define RecRegisterStatString(rec_type, name, data_default, persist_type) _RecRegisterStatString((rec_type), (name), (data_default), REC_PERSISTENCE_TYPE(persist_type))
00091 
00092 int _RecRegisterStatCounter(RecT rec_type, const char *name, RecCounter data_default, RecPersistT persist_type);
00093 #define RecRegisterStatCounter(rec_type, name, data_default, persist_type) _RecRegisterStatCounter((rec_type), (name), (data_default), REC_PERSISTENCE_TYPE(persist_type))
00094 
00095 //-------------------------------------------------------------------------
00096 // Config Registration
00097 //-------------------------------------------------------------------------
00098 
00099 int RecRegisterConfigInt(RecT rec_type, const char *name,
00100                          RecInt data_default, RecUpdateT update_type,
00101                          RecCheckT check_type, const char *ccheck_regex, RecAccessT access_type = RECA_NULL);
00102 
00103 int RecRegisterConfigFloat(RecT rec_type, const char *name,
00104                            RecFloat data_default, RecUpdateT update_type,
00105                            RecCheckT check_type, const char *check_regex, RecAccessT access_type = RECA_NULL);
00106 
00107 int RecRegisterConfigString(RecT rec_type, const char *name,
00108                             const char *data_default, RecUpdateT update_type,
00109                             RecCheckT check_type, const char *check_regex, RecAccessT access_type = RECA_NULL);
00110 
00111 int RecRegisterConfigCounter(RecT rec_type, const char *name,
00112                              RecCounter data_default, RecUpdateT update_type,
00113                              RecCheckT check_type, const char *check_regex, RecAccessT access_type = RECA_NULL);
00114 
00115 //-------------------------------------------------------------------------
00116 // Config Change Notification
00117 //-------------------------------------------------------------------------
00118 
00119 int RecLinkConfigInt(const char *name, RecInt * rec_int);
00120 int RecLinkConfigInt32(const char *name, int32_t * p_int32);
00121 int RecLinkConfigUInt32(const char *name, uint32_t * p_uint32);
00122 int RecLinkConfigFloat(const char *name, RecFloat * rec_float);
00123 int RecLinkConfigCounter(const char *name, RecCounter * rec_counter);
00124 int RecLinkConfigString(const char *name, RecString * rec_string);
00125 int RecLinkConfigByte(const char *name, RecByte * rec_byte);
00126 int RecLinkConfigBool(const char *name, RecBool * rec_byte);
00127 
00128 int RecRegisterConfigUpdateCb(const char *name, RecConfigUpdateCb update_cb, void *cookie);
00129 int RecRegisterRawStatUpdateFunc(const char *name, RecRawStatBlock * rsb, int id, RecStatUpdateFunc update_func, void *cookie);
00130 
00131 
00132 //-------------------------------------------------------------------------
00133 // Record Reading/Writing
00134 //-------------------------------------------------------------------------
00135 
00136 // WARNING!  Avoid deadlocks by calling the following set/get calls
00137 // with the appropiate locking conventions.  If you're calling these
00138 // functions from a configuration update callback (RecConfigUpdateCb),
00139 // be sure to set 'lock' to 'false' as the hash-table rwlock has
00140 // already been taken out for the callback.
00141 
00142 // RecSetRecordConvert -> WebMgmtUtils.cc::varSetFromStr()
00143 int RecSetRecordConvert(const char *name, const RecString rec_string, bool lock = true, bool inc_version = true);
00144 int RecSetRecordInt(const char *name, RecInt rec_int, bool lock = true, bool inc_version = true);
00145 int RecSetRecordFloat(const char *name, RecFloat rec_float, bool lock = true, bool inc_version = true);
00146 int RecSetRecordString(const char *name, const RecString rec_string, bool lock = true, bool inc_version = true);
00147 int RecSetRecordCounter(const char *name, RecCounter rec_counter, bool lock = true, bool inc_version = true);
00148 
00149 int RecGetRecordInt(const char *name, RecInt * rec_int, bool lock = true);
00150 int RecGetRecordFloat(const char *name, RecFloat * rec_float, bool lock = true);
00151 int RecGetRecordString(const char *name, char *buf, int buf_len, bool lock = true);
00152 int RecGetRecordString_Xmalloc(const char *name, RecString * rec_string, bool lock = true);
00153 int RecGetRecordCounter(const char *name, RecCounter * rec_counter, bool lock = true);
00154 // Convenience to allow us to treat the RecInt as a single byte internally
00155 int RecGetRecordByte(const char *name, RecByte * rec_byte, bool lock = true);
00156 // Convenience to allow us to treat the RecInt as a bool internally
00157 int RecGetRecordBool(const char *name, RecBool * rec_byte, bool lock = true);
00158 
00159 //------------------------------------------------------------------------
00160 // Record Attributes Reading
00161 //------------------------------------------------------------------------
00162 int RecGetRecordType(const char *name, RecT * rec_type, bool lock = true);
00163 int RecGetRecordDataType(const char *name, RecDataT * data_type, bool lock = true);
00164 int RecGetRecordPersistenceType(const char *name, RecPersistT * persist_type, bool lock = true);
00165 int RecGetRecordOrderAndId(const char *name, int *order, int *id, bool lock = true);
00166 
00167 int RecGetRecordUpdateType(const char *name, RecUpdateT * update_type, bool lock = true);
00168 int RecGetRecordCheckType(const char *name, RecCheckT * check_type, bool lock = true);
00169 int RecGetRecordCheckExpr(const char *name, char **check_expr, bool lock = true);
00170 int RecGetRecordDefaultDataString_Xmalloc(char *name, char **buf, bool lock = true);
00171 
00172 int RecGetRecordAccessType(const char *name, RecAccessT * secure, bool lock = true);
00173 int RecSetRecordAccessType(const char *name, RecAccessT secure, bool lock = true);
00174 
00175 void RecGetRecordTree(char *subtree = NULL);
00176 void RecGetRecordList(char *, char ***, int *);
00177 int RecGetRecordPrefix_Xmalloc(char *prefix, char **result, int *result_len);
00178 
00179 
00180 //------------------------------------------------------------------------
00181 // Signal and Alarms
00182 //------------------------------------------------------------------------
00183 
00184 // RecSignalManager always sends a management signal up to traffic_manager.
00185 void RecSignalManager(int id, const char * , size_t);
00186 
00187 static inline void
00188 RecSignalManager(int id, const char * str) {
00189   RecSignalManager(id, str, strlen(str + 1));
00190 }
00191 
00192 // Format a message, and send it to the manager and to the Warning diagnostic.
00193 void RecSignalWarning(int sig, const char * fmt, ...)
00194   TS_PRINTFLIKE(2, 3);
00195 
00196 //-------------------------------------------------------------------------
00197 // Backwards Compatibility Items (REC_ prefix)
00198 //-------------------------------------------------------------------------
00199 #define REC_ReadConfigInt32(_var,_config_var_name) do { \
00200   RecInt tmp = 0; \
00201   RecGetRecordInt(_config_var_name, (RecInt*) &tmp); \
00202   _var = (int32_t)tmp; \
00203 } while (0)
00204 
00205 #define REC_ReadConfigInteger(_var,_config_var_name) do { \
00206   RecInt tmp = 0; \
00207   RecGetRecordInt(_config_var_name, &tmp); \
00208   _var = tmp; \
00209 } while (0)
00210 
00211 #define REC_ReadConfigFloat(_var,_config_var_name) do { \
00212   RecFloat tmp = 0; \
00213   RecGetRecordFloat(_config_var_name, &tmp); \
00214   _var = tmp; \
00215 } while (0)
00216 
00217 #define REC_ReadConfigStringAlloc(_var,_config_var_name) \
00218   RecGetRecordString_Xmalloc(_config_var_name, (RecString*)&_var)
00219 
00220 #define REC_ReadConfigString(_var, _config_var_name, _len) \
00221   RecGetRecordString(_config_var_name, _var, _len)
00222 
00223 #define REC_RegisterConfigUpdateFunc(_config_var_name, func, flag) \
00224   RecRegisterConfigUpdateCb(_config_var_name, func, flag)
00225 
00226 #define REC_EstablishStaticConfigInteger(_var, _config_var_name) do { \
00227   RecLinkConfigInt(_config_var_name, &_var); \
00228   _var = (int64_t)REC_ConfigReadInteger(_config_var_name); \
00229 } while (0)
00230 
00231 #define REC_EstablishStaticConfigInt32(_var, _config_var_name) do { \
00232   RecLinkConfigInt32(_config_var_name, &_var); \
00233   _var = (int32_t)REC_ConfigReadInteger(_config_var_name); \
00234 } while (0)
00235 
00236 #define REC_EstablishStaticConfigInt32U(_var, _config_var_name) do { \
00237   RecLinkConfigUInt32(_config_var_name, &_var); \
00238   _var = (int32_t)REC_ConfigReadInteger(_config_var_name); \
00239 } while (0)
00240 
00241 /*
00242  * RecLinkConfigString allocates the RecString and stores the ptr to it (&var).
00243  * So before changing _var (the RecString) we have to free the original one.
00244  * Really, we somehow need to know whether RecLinkConfigString allocated _var.
00245  * For now, we're using the return value to indicate this, even though it's
00246  * not always the case.  If we're wrong, we'll leak the RecString.
00247  */
00248 #define REC_EstablishStaticConfigStringAlloc(_var, _config_var_name) do { \
00249   if (RecLinkConfigString(_config_var_name, &_var) == REC_ERR_OKAY) \
00250     ats_free(_var);                                                    \
00251   _var = (RecString)REC_ConfigReadString(_config_var_name); \
00252 } while (0)
00253 
00254 #define REC_EstablishStaticConfigFloat(_var, _config_var_name) do { \
00255   RecLinkConfigFloat(_config_var_name, &_var); \
00256   _var = (RecFloat)REC_ConfigReadFloat(_config_var_name); \
00257 } while (0)
00258 
00259 // Allow to treat our "INT" configs as a byte type internally. Note
00260 // that the byte type is just a wrapper around RECD_INT.
00261 #define REC_EstablishStaticConfigByte(_var, _config_var_name) do { \
00262     RecLinkConfigByte(_config_var_name, &_var); \
00263     _var = (RecByte)REC_ConfigReadInteger(_config_var_name);    \
00264   } while (0)
00265 
00266 // Allow to treat our "INT" configs as a bool type internally. Note
00267 // that the bool type is just a wrapper around RECD_INT.
00268 #define REC_EstablishStaticConfigBool(_var, _config_var_name) do { \
00269     RecLinkConfigBool(_config_var_name, &_var); \
00270     _var = 0 != REC_ConfigReadInteger(_config_var_name);    \
00271   } while (0)
00272 
00273 RecInt REC_ConfigReadInteger(const char *name);
00274 char *REC_ConfigReadString(const char *name);
00275 RecFloat REC_ConfigReadFloat(const char *name);
00276 RecCounter REC_ConfigReadCounter(const char *name);
00277 
00278 // MGMT2 Marco's -- converting lmgmt->record_data->readXXX
00279 RecInt REC_readInteger(const char *name, bool * found, bool lock = true);
00280 RecFloat REC_readFloat(char *name, bool * found, bool lock = true);
00281 RecCounter REC_readCounter(char *name, bool * found, bool lock = true);
00282 RecString REC_readString(const char *name, bool * found, bool lock = true);
00283 
00284 //------------------------------------------------------------------------
00285 // Clear Statistics
00286 //------------------------------------------------------------------------
00287 int RecResetStatRecord(const char *name);
00288 int RecResetStatRecord(RecT type = RECT_NULL, bool all = false);
00289 
00290 
00291 //------------------------------------------------------------------------
00292 // Set RecRecord attributes
00293 //------------------------------------------------------------------------
00294 int RecSetSyncRequired(char *name, bool lock = true);
00295 
00296 //------------------------------------------------------------------------
00297 // Manager Callback
00298 //------------------------------------------------------------------------
00299 typedef void *(*RecManagerCb) (void *opaque_cb_data, char *data_raw, int data_len);
00300 int RecRegisterManagerCb(int _signal, RecManagerCb _fn, void *_data = NULL);
00301 
00302 void RecResizeAdditional(int add);
00303 
00304 #endif

Generated by  doxygen 1.7.1