aboutsummaryrefslogtreecommitdiff
path: root/contrib/otshell_utils/runoptions.cpp
diff options
context:
space:
mode:
authorrfree2monero <rfreemonero@op.pl>2015-01-05 20:30:17 +0100
committerrfree2monero <rfreemonero@op.pl>2015-02-20 22:13:00 +0100
commiteabb519605cab00dbaa5a1868d229f09c74570a6 (patch)
tree42f909d8e94e8cf67836d57cef4053ac572e3f8c /contrib/otshell_utils/runoptions.cpp
parentMerge pull request #229 (diff)
downloadmonero-eabb519605cab00dbaa5a1868d229f09c74570a6.tar.xz
2014 network limit 1.0a +utils +toc -doc -drmonero
commands and options for network limiting works very well e.g. for 50 KiB/sec up and down ToS (QoS) flag peer number limit TODO some spikes in ingress/download TODO problems when other up and down limit added "otshell utils" - simple logging (with colors, text files channels)
Diffstat (limited to 'contrib/otshell_utils/runoptions.cpp')
-rw-r--r--contrib/otshell_utils/runoptions.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/contrib/otshell_utils/runoptions.cpp b/contrib/otshell_utils/runoptions.cpp
new file mode 100644
index 000000000..28e7ceb58
--- /dev/null
+++ b/contrib/otshell_utils/runoptions.cpp
@@ -0,0 +1,69 @@
+/* See other files here for the LICENCE that applies here. */
+/* See header file .hpp for info */
+
+#include "runoptions.hpp"
+
+#include "lib_common1.hpp"
+
+namespace nOT {
+
+INJECT_OT_COMMON_USING_NAMESPACE_COMMON_1; // <=== namespaces
+
+// (no debug - this is the default)
+// +nodebug (no debug)
+// +debug ...... --asdf
+// +debug +debugcerr .... --asfs
+// +debug +debugfile .... --asfs
+
+cRunOptions::cRunOptions()
+ : mRunMode(eRunModeCurrent), mDebug(false), mDebugSendToFile(false), mDebugSendToCerr(false)
+ ,mDoRunDebugshow(false)
+{ }
+
+vector<string> cRunOptions::ExecuteRunoptionsAndRemoveThem(const vector<string> & args) {
+ vector<string> arg_clear; // will store only the arguments that are not removed
+
+ for (auto arg : args) {
+ bool thisIsRunoption=false;
+
+ if (arg.size()>0) {
+ if (arg.at(0) == '+') thisIsRunoption=true;
+ }
+
+ if (thisIsRunoption) Exec(arg); // ***
+ if (! thisIsRunoption) arg_clear.push_back(arg);
+ }
+
+ Normalize();
+
+ return arg_clear;
+}
+
+void cRunOptions::Exec(const string & runoption) { // eg: Exec("+debug");
+ if (runoption == "+nodebug") { mDebug=false; }
+ else if (runoption == "+debug") { mDebug=true; }
+ else if (runoption == "+debugcerr") { mDebug=true; mDebugSendToCerr=true; }
+ else if (runoption == "+debugfile") { mDebug=true; mDebugSendToFile=true; }
+ else if (runoption == "+demo") { mRunMode=eRunModeDemo; }
+ else if (runoption == "+normal") { mRunMode=eRunModeNormal; }
+ else if (runoption == "+current") { mRunMode=eRunModeCurrent; }
+ else if (runoption == "+debugshow") { mDebug=true; mDebugSendToCerr=true; mDoRunDebugshow=true; }
+ else {
+ cerr << "Unknown runoption in Exec: '" << runoption << "'" << endl;
+ throw std::runtime_error("Unknown runoption");
+ }
+ // cerr<<"debug="<<mDebug<<endl;
+}
+
+void cRunOptions::Normalize() {
+ if (mDebug) {
+ if (!( mDebugSendToFile || mDebugSendToCerr )) mDebugSendToCerr=true; // if debug is on then send to something, e.g. to cerr
+ }
+}
+
+
+cRunOptions gRunOptions; // (extern)
+
+}; // namespace OT
+
+