| 1 | #include <iostream>
|
|---|
| 2 | #include <dic.hxx>
|
|---|
| 3 | using namespace std;
|
|---|
| 4 |
|
|---|
| 5 | class ErrorHandler : public DimErrorHandler
|
|---|
| 6 | {
|
|---|
| 7 | void errorHandler(int severity, int code, char *msg)
|
|---|
| 8 | {
|
|---|
| 9 | int index = 0;
|
|---|
| 10 | char **services;
|
|---|
| 11 | cout << severity << " " << msg << endl;
|
|---|
| 12 | services = DimClient::getServerServices();
|
|---|
| 13 | cout<< "from "<< DimClient::getServerName() << " services:" << endl;
|
|---|
| 14 | while(services[index])
|
|---|
| 15 | {
|
|---|
| 16 | cout << services[index] << endl;
|
|---|
| 17 | index++;
|
|---|
| 18 | }
|
|---|
| 19 | }
|
|---|
| 20 | public:
|
|---|
| 21 | ErrorHandler() {DimClient::addErrorHandler(this);}
|
|---|
| 22 | };
|
|---|
| 23 |
|
|---|
| 24 | class StrService : public DimInfo
|
|---|
| 25 | {
|
|---|
| 26 |
|
|---|
| 27 | void infoHandler()
|
|---|
| 28 | {
|
|---|
| 29 | int index = 0;
|
|---|
| 30 | char **services;
|
|---|
| 31 | // cout << "Dns Node = " << DimClient::getDnsNode() << endl;
|
|---|
| 32 | cout << "Received STRVAL : " << getString() << endl;
|
|---|
| 33 | services = DimClient::getServerServices();
|
|---|
| 34 | cout<< "from "<< DimClient::getServerName() << " services:" << endl;
|
|---|
| 35 | while(services[index])
|
|---|
| 36 | {
|
|---|
| 37 | cout << services[index] << endl;
|
|---|
| 38 | index++;
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|
| 41 | public :
|
|---|
| 42 | StrService() : DimInfo("TEST/STRVAL","not available") {};
|
|---|
| 43 | };
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | void **AllServices;
|
|---|
| 47 | int *AllServiceStates;
|
|---|
| 48 | int NServices;
|
|---|
| 49 | int NBytes;
|
|---|
| 50 |
|
|---|
| 51 | class MyTimer: public DimTimer
|
|---|
| 52 | {
|
|---|
| 53 | void timerHandler()
|
|---|
| 54 | {
|
|---|
| 55 | int i;
|
|---|
| 56 | int missing = 0;
|
|---|
| 57 | for(i = 0; i < NServices; i++)
|
|---|
| 58 | {
|
|---|
| 59 | if(AllServiceStates[i] == -2)
|
|---|
| 60 | {
|
|---|
| 61 | missing++;
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| 64 | dim_print_date_time();
|
|---|
| 65 | printf("Missing %d, NBytes = %d\n", missing, NBytes);
|
|---|
| 66 | if(missing)
|
|---|
| 67 | start(1);
|
|---|
| 68 | }
|
|---|
| 69 | public:
|
|---|
| 70 | MyTimer(): DimTimer(2){};
|
|---|
| 71 | };
|
|---|
| 72 |
|
|---|
| 73 | class TestGetService: public DimInfo
|
|---|
| 74 | {
|
|---|
| 75 | void infoHandler()
|
|---|
| 76 | {
|
|---|
| 77 | int i, index, size, done = 1;
|
|---|
| 78 | char *dataptr;
|
|---|
| 79 |
|
|---|
| 80 | size = getSize();
|
|---|
| 81 | NBytes += size;
|
|---|
| 82 | dataptr = new char[size];
|
|---|
| 83 | memcpy(dataptr, getData(), size);
|
|---|
| 84 | for(i = 0; i < NServices; i++)
|
|---|
| 85 | {
|
|---|
| 86 | if(AllServices[i] == this)
|
|---|
| 87 | {
|
|---|
| 88 | index = i;
|
|---|
| 89 | break;
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 | AllServiceStates[index] = getInt();
|
|---|
| 93 | // printf("Got %s, %d, %d\n", getName(), index, AllServiceStates[index]);
|
|---|
| 94 | for(i = 0; i < NServices; i++)
|
|---|
| 95 | {
|
|---|
| 96 | if(AllServiceStates[i] == -2)
|
|---|
| 97 | {
|
|---|
| 98 | done = 0;
|
|---|
| 99 | break;
|
|---|
| 100 | }
|
|---|
| 101 | }
|
|---|
| 102 | if(done)
|
|---|
| 103 | {
|
|---|
| 104 | dim_print_date_time();
|
|---|
| 105 | printf("All Services Received\n");
|
|---|
| 106 | }
|
|---|
| 107 | }
|
|---|
| 108 | public :
|
|---|
| 109 | TestGetService(char *name): DimInfo(name, -1){};
|
|---|
| 110 | };
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 | int main(int argc, char **argv)
|
|---|
| 114 | {
|
|---|
| 115 |
|
|---|
| 116 | ErrorHandler errHandler;
|
|---|
| 117 | // StrService servstr;
|
|---|
| 118 | char *server, *ptr, *ptr1;
|
|---|
| 119 | DimBrowser br;
|
|---|
| 120 | int type, n, index, i, ret;
|
|---|
| 121 | MyTimer *myTimer;
|
|---|
| 122 | char findStr[132];
|
|---|
| 123 |
|
|---|
| 124 | ret = 0;
|
|---|
| 125 | strcpy(findStr,"*");
|
|---|
| 126 | if(argc > 1)
|
|---|
| 127 | {
|
|---|
| 128 | if(!strcmp(argv[1],"-f"))
|
|---|
| 129 | {
|
|---|
| 130 | if(argc > 2)
|
|---|
| 131 | strcpy(findStr,argv[2]);
|
|---|
| 132 | else
|
|---|
| 133 | ret = 1;
|
|---|
| 134 | }
|
|---|
| 135 | else
|
|---|
| 136 | ret = 1;
|
|---|
| 137 | if(ret)
|
|---|
| 138 | {
|
|---|
| 139 | printf("Parameters: [-f <search string>]\n");
|
|---|
| 140 | exit(0);
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| 143 | // DimClient::addErrorHandler(errHandler);
|
|---|
| 144 | dim_print_date_time();
|
|---|
| 145 | printf("Asking %s\n", findStr);
|
|---|
| 146 | n = br.getServices(findStr);
|
|---|
| 147 | dim_print_date_time();
|
|---|
| 148 | cout << "found " << n << " services" << endl;
|
|---|
| 149 |
|
|---|
| 150 | AllServices = (void **) new TestGetService*[n];
|
|---|
| 151 | AllServiceStates = new int[n];
|
|---|
| 152 | NServices = n;
|
|---|
| 153 | NBytes = 0;
|
|---|
| 154 | index = 0;
|
|---|
| 155 | for(i = 0; i < n; i++)
|
|---|
| 156 | AllServiceStates[i] = 0;
|
|---|
| 157 | while((type = br.getNextService(ptr, ptr1))!= 0)
|
|---|
| 158 | {
|
|---|
| 159 |
|
|---|
| 160 | // cout << "type = " << type << " - " << ptr << " " << ptr1 << endl;
|
|---|
| 161 | AllServiceStates[index] = -2;
|
|---|
| 162 | AllServices[index] = new TestGetService(ptr);
|
|---|
| 163 | index++;
|
|---|
| 164 | // if(index >= 1000)
|
|---|
| 165 | // break;
|
|---|
| 166 | }
|
|---|
| 167 | myTimer = new MyTimer();
|
|---|
| 168 | dim_print_date_time();
|
|---|
| 169 | printf("Got Service Names\n");
|
|---|
| 170 | /*
|
|---|
| 171 | br.getServers();
|
|---|
| 172 | while(br.getNextServer(server, ptr1))
|
|---|
| 173 | {
|
|---|
| 174 | cout << server << " @ " << ptr1 << endl;
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | br.getServerClients("DIS_DNS");
|
|---|
| 178 | while(br.getNextServerClient(ptr, ptr1))
|
|---|
| 179 | {
|
|---|
| 180 | cout << ptr << " @ " << ptr1 << endl;
|
|---|
| 181 | }
|
|---|
| 182 | DimInfo servint("TEST/INTVAL",-1);
|
|---|
| 183 | */
|
|---|
| 184 | while(1)
|
|---|
| 185 | {
|
|---|
| 186 | sleep(10);
|
|---|
| 187 | /*
|
|---|
| 188 | cout << "Current INTVAL : " << servint.getInt() << endl;
|
|---|
| 189 | DimClient::sendCommand("TEST/CMND","UPDATE_STRVAL");
|
|---|
| 190 | */
|
|---|
| 191 | }
|
|---|
| 192 | return 0;
|
|---|
| 193 | }
|
|---|