00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "crompish_pax.h"
00020
00021 #include <basis/chaos.h>
00022 #include <basis/istring.h>
00023 #include <basis/portable.h>
00024 #include <data_struct/amorph.cpp>
00025 #include <cromp/cromp_client.h>
00026 #include <octopus/entity_defs.h>
00027 #include <octopus/infoton.h>
00028 #include <opsystem/application_shell.h>
00029 #include <opsystem/command_line.h>
00030 #include <loggers/console_logger.h>
00031 #include <loggers/file_logger.h>
00032 #include <data_struct/static_memory_gremlin.h>
00033 #include <sockets/address.h>
00034
00035 #include <stdio.h>
00036
00037 #define DEBUG_TESTER
00038
00039
00040 const int REPORTING_INTERVAL = 20 * SECOND_ms;
00041
00042
00043 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger(), s)
00044 #define BASE_LOG(s) EMERGENCY_LOG(program_wide_logger(), s)
00045
00046 class many_cromp_tester : public application_shell
00047 {
00048 public:
00049 many_cromp_tester();
00050 ~many_cromp_tester();
00051
00052 virtual int execute();
00053
00054 IMPLEMENT_CLASS_NAME("many_cromp_tester");
00055
00056 private:
00057 amorph<cromp_client> _uplinks;
00058 bool _encryption;
00059 int _count;
00060 };
00061
00063
00064 many_cromp_tester::many_cromp_tester()
00065 : application_shell("many_cromp_tester"),
00066 _uplinks(),
00067 _encryption(false),
00068 _count(1)
00069 {
00070 FUNCDEF("constructor");
00071 LOG("");
00072 LOG("");
00073
00074 internet_address server_loc;
00075
00076 command_line args(__argc, __argv);
00077
00078
00079
00080 istring port_text;
00081 int port = 5678;
00082 if (args.get_value("port", port_text, false)) {
00083 LOG(istring("using port: ") + port_text);
00084 port = port_text.convert(5678);
00085 }
00086 server_loc.port = port;
00087
00088 istring count_text;
00089 if (args.get_value("count", count_text, false)) {
00090 LOG(istring("using count: ") + count_text);
00091 _count = count_text.convert(_count);
00092 }
00093
00094
00095
00096 int indy = 0;
00097 if (args.find("encrypt", indy, false)
00098 || (args.find('e', indy, false)) ) {
00099
00100 _encryption = true;
00101 }
00102
00103
00104 istring hostname("local");
00105 istring host_temp;
00106 if (args.get_value("host", host_temp, false)) {
00107 LOG(istring("using host: ") + host_temp);
00108 hostname = host_temp;
00109 }
00110 LOG(istring("using host: ") + hostname);
00111 strcpy(server_loc.hostname, hostname.s());
00112
00113 LOG(istring("opening at ") + server_loc.text_form());
00114
00115 LOG(isprintf("count of %d cromps will be created.", _count));
00116
00117 for (int i = 0; i < _count; i++) {
00118 LOG(isprintf("%d. A", i));
00119 cromp_client *uplink = new cromp_client(server_loc);
00120 LOG(isprintf("%d. B", i));
00121 uplink->add_tentacle(new bubbles_tentacle(false));
00122 LOG(isprintf("%d. C", i));
00123 _uplinks.append(uplink);
00124 }
00125
00126 }
00127
00128 many_cromp_tester::~many_cromp_tester()
00129 {
00130 }
00131
00132 int many_cromp_tester::execute()
00133 {
00134 FUNCDEF("execute");
00135
00136 if (_encryption) {
00137 for (int i = 0; i < _uplinks.elements(); i++) {
00138 _uplinks.borrow(i)->enable_encryption();
00139 }
00140 }
00141
00142 for (int i = 0; i < _uplinks.elements(); i++) {
00143 outcome ret = _uplinks.borrow(i)->connect();
00144 if (ret != cromp_client::OKAY) {
00145 deadly_error(class_name(), func, istring("connection failed with error: ")
00146 + cromp_client::outcome_name(ret));
00147 }
00148 }
00149
00150 time_stamp when_to_leave(10 * HOUR_ms);
00151
00152 time_stamp next_report(REPORTING_INTERVAL);
00153
00154 while (time_stamp() < when_to_leave) {
00155 int unconnected = 0;
00156 for (int i = 0; i < _uplinks.elements(); i++) {
00157 if (!_uplinks.borrow(i)->connected())
00158 unconnected++;
00159 }
00160
00161 if (time_stamp() > next_report) {
00162 int connected = _uplinks.elements() - unconnected;
00163 LOG(isprintf("[ %d connected and %d did not ]", connected, unconnected));
00164 next_report.reset(REPORTING_INTERVAL);
00165 }
00166
00167
00168
00169 portable::sleep_ms(100);
00170 }
00171
00172
00173 BASE_LOG("many cromp_client:: works for those functions tested.");
00174
00175 return 0;
00176 }
00177
00179
00180 HOOPLE_MAIN(many_cromp_tester, )
00181