Sirikata
|
00001 /* Sirikata 00002 * CommonOptions.hpp 00003 * 00004 * Copyright (c) 2009, Ewen Cheslack-Postava 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are 00009 * met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in 00014 * the documentation and/or other materials provided with the 00015 * distribution. 00016 * * Neither the name of Sirikata nor the names of its contributors may 00017 * be used to endorse or promote products derived from this software 00018 * without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00021 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00022 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00023 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00024 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 */ 00032 00033 #ifndef _SIRIKATA_COMMON_OPTIONS_HPP_ 00034 #define _SIRIKATA_COMMON_OPTIONS_HPP_ 00035 00036 #include <sirikata/core/util/Platform.hpp> 00037 00038 #define OPT_CRASHREPORT_URL "crashreport" 00039 00040 #define OPT_PLUGINS "plugins" 00041 #define OPT_EXTRA_PLUGINS "extra-plugins" 00042 00043 #define OPT_LOG_FILE "log-file" 00044 #define OPT_LOG_ALL_TO_FILE "log-all-to-file" 00045 #define OPT_DAEMON "daemon" 00046 #define OPT_PID_FILE "pid-file" 00047 00048 #define OPT_SST_DEFAULT_WINDOW_SIZE "sst.default-window-size" 00049 00050 #define STATS_TRACE_FILE "stats.trace-filename" 00051 #define PROFILE "profile" 00052 00053 #define OPT_REGION_WEIGHT "region-weight" 00054 #define OPT_REGION_WEIGHT_ARGS "region-weight-args" 00055 00056 #define OPT_CDN_HOST "cdn.host" 00057 #define OPT_CDN_SERVICE "cdn.service" 00058 #define OPT_CDN_DNS_URI_PREFIX "cdn.dns.prefix" 00059 #define OPT_CDN_DOWNLOAD_URI_PREFIX "cdn.download.prefix" 00060 #define OPT_CDN_UPLOAD_URI_PREFIX "cdn.upload.prefix" 00061 #define OPT_CDN_UPLOAD_STATUS_URI_PREFIX "cdn.upload.status.prefix" 00062 00063 #define OPT_TRACE_TIMESERIES "trace.timeseries" 00064 #define OPT_TRACE_TIMESERIES_OPTIONS "trace.timeseries-options" 00065 00066 #define OPT_COMMAND_COMMANDER "command.commander" 00067 #define OPT_COMMAND_COMMANDER_OPTIONS "command.commander-options" 00068 00069 namespace Sirikata { 00070 00072 SIRIKATA_FUNCTION_EXPORT void ReportVersion(); 00073 00074 SIRIKATA_FUNCTION_EXPORT void InitOptions(); 00075 00076 enum UnregisteredOptionBehavior { 00077 AllowUnregisteredOptions, 00078 FailOnUnregisteredOptions 00079 }; 00080 00081 SIRIKATA_FUNCTION_EXPORT void ParseOptions(int argc, char** argv, UnregisteredOptionBehavior unreg = FailOnUnregisteredOptions); 00082 SIRIKATA_FUNCTION_EXPORT void ParseOptionsFile(const String& fname, bool required=true, UnregisteredOptionBehavior unreg = FailOnUnregisteredOptions); 00083 00088 SIRIKATA_FUNCTION_EXPORT void ParseOptions(int argc, char** argv, const String& config_file_option, UnregisteredOptionBehavior unreg = FailOnUnregisteredOptions); 00089 00090 // Parses empty options to get options properly initialized 00091 SIRIKATA_FUNCTION_EXPORT void FakeParseOptions(); 00092 00096 SIRIKATA_FUNCTION_EXPORT void FillMissingOptionDefaults(); 00097 00098 00101 SIRIKATA_FUNCTION_EXPORT void DaemonizeAndSetOutputs(); 00102 SIRIKATA_FUNCTION_EXPORT void DaemonCleanup(); 00103 00104 // Be careful with GetOption. Using it and ->as() directly can be dangerous 00105 // because some types are defined per-library and won't dynamic_cast properly. 00106 // It is suggested that you use GetOptionValue where possible. 00107 SIRIKATA_FUNCTION_EXPORT OptionValue* GetOption(const char* name); 00108 SIRIKATA_FUNCTION_EXPORT OptionValue* GetOption(const char* klass, const char* name); 00109 00110 template<typename T> 00111 T GetOptionValue(const char* name) { 00112 OptionValue* opt = GetOption(name); 00113 return opt->as<T>(); 00114 } 00115 00116 template<typename T> 00117 T GetOptionValue(const char* klass, const char* name) { 00118 OptionValue* opt = GetOption(klass, name); 00119 return opt->unsafeAs<T>(); // FIXME should be ->as<T>(); 00120 } 00121 00122 template<> 00123 SIRIKATA_FUNCTION_EXPORT String GetOptionValue<String>(const char* name); 00124 template<> 00125 SIRIKATA_FUNCTION_EXPORT Vector3f GetOptionValue<Vector3f>(const char* name); 00126 template<> 00127 SIRIKATA_FUNCTION_EXPORT Vector3ui32 GetOptionValue<Vector3ui32>(const char* name); 00128 template<> 00129 SIRIKATA_FUNCTION_EXPORT BoundingBox3f GetOptionValue<BoundingBox3f>(const char* name); 00130 template<> 00131 SIRIKATA_FUNCTION_EXPORT ObjectHostID GetOptionValue<ObjectHostID>(const char* name); 00132 template<> 00133 SIRIKATA_FUNCTION_EXPORT Task::DeltaTime GetOptionValue<Task::DeltaTime>(const char* name); 00134 template<> 00135 SIRIKATA_FUNCTION_EXPORT uint32 GetOptionValue<uint32>(const char* name); 00136 template<> 00137 SIRIKATA_FUNCTION_EXPORT int32 GetOptionValue<int32>(const char* name); 00138 template<> 00139 SIRIKATA_FUNCTION_EXPORT uint64 GetOptionValue<uint64>(const char* name); 00140 template<> 00141 SIRIKATA_FUNCTION_EXPORT int64 GetOptionValue<int64>(const char* name); 00142 template<> 00143 SIRIKATA_FUNCTION_EXPORT bool GetOptionValue<bool>(const char* name); 00144 00145 00146 SIRIKATA_FUNCTION_EXPORT String GetPerServerString(const String& orig, const ServerID& sid); 00148 SIRIKATA_FUNCTION_EXPORT String GetPerServerFile(const char* opt_name, const ServerID& sid); 00149 SIRIKATA_FUNCTION_EXPORT String GetPerServerFile(const char* opt_name, const ObjectHostID& ohid); 00150 00151 } // namespace Sirikata 00152 00153 00154 #endif //_SIRIKATA_COMMON_OPTIONS_HPP_