LCOV - code coverage report
Current view: top level - src - discpp.cxx (source / functions) Hit Total Coverage
Test: lcov.info Lines: 89 892 10.0 %
Date: 2025-03-09 01:23:52 Functions: 11 148 7.4 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : #define DIMLIB
       2                 :            : #include <dis.hxx>
       3                 :            : #include "tokenstring.hxx"
       4                 :            : //#include <iostream>
       5                 :            : //using namespace std;
       6                 :            : #include <time.h>
       7                 :            : //#include <sys/timeb.h>
       8                 :            : 
       9                 :            : DimClientExitHandler *DimServer::itsClientExit = 0;
      10                 :            : DimExitHandler *DimServer::itsExit = 0;
      11                 :            : DimErrorHandler *DimServer::itsSrvError = 0;
      12                 :            : char *DimServer::itsName = 0;
      13                 :            : char *DimServer::clientName = 0;
      14                 :            : char *DimServer::dimDnsNode = 0;
      15                 :            : int DimServer::autoStart = 1;
      16                 :            : //int DimServer::itsNServices = 0;
      17                 :            : 
      18                 :            : extern "C" {
      19                 :            : extern void dis_init();
      20                 :            : extern int do_dis_remove_service(unsigned service_id, int do_stop_serving, void **dnsp );
      21                 :            : extern void do_dis_stop_serving_dns(void *dnsp);
      22                 :            : 
      23                 :          5 : static void user_routine( void *tagp, void **buf, int *size, int *first_time)
      24                 :            : {
      25                 :            : //      int *tag = (int *)tagp;
      26                 :            : //      int id = *tag;
      27                 :            :         DimService *t;
      28                 :            : 
      29                 :            :         if(first_time){}
      30                 :            : //      t = (DimService *)id_get_ptr(id, SRC_DIS);
      31                 :          5 :         t = *(DimService **)tagp;
      32                 :          5 :         if( t->itsServiceHandler ) {
      33                 :          0 :                 t->itsServiceHandler->itsService = t;
      34                 :          0 :                 DimCore::inCallback = 2;
      35                 :          0 :                 t->itsServiceHandler->serviceHandler();
      36                 :          0 :                 DimCore::inCallback = 0;
      37                 :            :         }
      38                 :            :         else
      39                 :            :         {
      40                 :          5 :                 DimCore::inCallback = 2;
      41                 :          5 :                 t->serviceHandler();
      42                 :          5 :                 DimCore::inCallback = 0;
      43                 :            :         }
      44                 :          5 :         if( t->itsType == DisSTRING)
      45                 :          0 :                         t->itsSize = (int)strlen((char *)t->itsData)+1;
      46                 :          5 :         *buf = t->itsData;
      47                 :          5 :         *size = t->itsSize;
      48                 :          5 : }
      49                 :            : }
      50                 :            : 
      51                 :          3 : void DimService::declareIt(char *name, char *format, DimServiceHandler *handler, DimServerDns *dns)
      52                 :            : {
      53                 :            : //      itsTagId = 0;
      54                 :          3 :         itsDns = dns;
      55                 :          3 :         itsName = new char[(int)strlen(name)+1];
      56                 :          3 :         strcpy( itsName, name);
      57                 :          3 :         if(handler)
      58                 :          0 :                 itsServiceHandler = handler;
      59                 :            :         else
      60                 :          3 :                 itsServiceHandler = 0;
      61                 :            : //      itsTagId = id_get((void *)this, SRC_DIS);
      62                 :          3 :         dis_init();
      63                 :          3 :         if(itsDns == 0)
      64                 :            :         {
      65                 :          3 :                 DISABLE_AST
      66                 :          3 :                 itsId = dis_add_service( name, format, NULL, 0,
      67                 :            : //                              user_routine, itsTagId);
      68                 :            :                                 user_routine, (dim_long)this);
      69                 :          3 :                 ENABLE_AST
      70                 :          3 :                 DimServer::start();
      71                 :            :         }
      72                 :            :         else
      73                 :            :         {
      74                 :          0 :                 DISABLE_AST
      75                 :          0 :                 itsId = dis_add_service_dns( itsDns->getDnsId(), name, format, NULL, 0,
      76                 :            : //                              user_routine, itsTagId);
      77                 :            :                                 user_routine, (dim_long)this);
      78                 :          0 :                 ENABLE_AST
      79                 :            : //              itsDns->addServiceId(itsId);
      80                 :          0 :                 DimServer::start(itsDns);
      81                 :            :         }
      82                 :          3 : }
      83                 :            : 
      84                 :          7 : void DimService::storeIt(const void *data, int size)
      85                 :            : {
      86                 :          7 :         DISABLE_AST
      87                 :          7 :         if(!itsDataSize)
      88                 :            :         {
      89                 :          3 :                 itsData = new char[size];
      90                 :          3 :                 itsDataSize = size;
      91                 :            :         }
      92                 :          4 :         else if(itsDataSize < size)
      93                 :            :         {
      94                 :          0 :                 delete[] (char *)itsData;
      95                 :          0 :                 itsData = new char[size];
      96                 :          0 :                 itsDataSize = size;
      97                 :            :         }
      98                 :          7 :         memcpy(itsData, data, (size_t)size);
      99                 :          7 :         itsSize = size;
     100                 :          7 :         ENABLE_AST
     101                 :          7 : }
     102                 :            : 
     103                 :            : extern "C" {
     104                 :          0 : static void command_routine( void *tagp, void *buf, int *size)
     105                 :            : {
     106                 :            : //      int *tag = (int *)tagp;
     107                 :            : //      int id = *tag;
     108                 :            :         DimCommand *t;
     109                 :            : 
     110                 :            : //      t = (DimCommand *)id_get_ptr(id, SRC_DIS);
     111                 :          0 :         t = *(DimCommand **)tagp;
     112                 :          0 :         t->itsData = buf;
     113                 :          0 :         t->itsSize = *size;
     114                 :          0 :         t->secs = 0;
     115                 :          0 :         if( t->itsCommandHandler ) {
     116                 :          0 :                 t->itsCommandHandler->itsCommand = t;
     117                 :          0 :                 DimCore::inCallback = 2;
     118                 :          0 :                 t->itsCommandHandler->commandHandler();
     119                 :          0 :                 DimCore::inCallback = 0;
     120                 :            :         }
     121                 :            :         else
     122                 :            :         {
     123                 :          0 :                 DimCore::inCallback = 2;
     124                 :          0 :                 t->commandHandler();
     125                 :          0 :                 DimCore::inCallback = 0;
     126                 :            :         }
     127                 :          0 :         t->itsData = 0;
     128                 :          0 :         t->itsSize = 0;
     129                 :          0 : }
     130                 :            : }
     131                 :            : 
     132                 :          0 : void DimCommand::declareIt(char *name, char *format, DimCommandHandler *handler, DimServerDns *dns)
     133                 :            : {
     134                 :            : //      itsTagId = 0;
     135                 :          0 :         itsId = 0;
     136                 :          0 :         itsDns = dns;
     137                 :          0 :         itsName = new char[(int)strlen(name)+1];
     138                 :          0 :         strcpy( itsName, name);
     139                 :          0 :         itsFormat = new char[(int)strlen(format)+1];
     140                 :          0 :         strcpy( itsFormat, format);
     141                 :          0 :         currCmnd = 0;
     142                 :          0 :         if(handler)
     143                 :          0 :                 itsCommandHandler = handler;
     144                 :            :         else
     145                 :          0 :                 itsCommandHandler = 0;
     146                 :            : //      itsTagId = id_get((void *)this, SRC_DIS);
     147                 :          0 :         dis_init();
     148                 :          0 :         if(!itsDns)
     149                 :            :         {
     150                 :          0 :                 DISABLE_AST
     151                 :          0 :                 itsId = dis_add_cmnd( name, format, command_routine,
     152                 :            : //                              itsTagId);
     153                 :            :                                 (dim_long)this);
     154                 :          0 :                 ENABLE_AST
     155                 :          0 :                 DimServer::start();
     156                 :            :         }
     157                 :            :         else
     158                 :            :         {
     159                 :          0 :                 DISABLE_AST
     160                 :          0 :                 itsId = dis_add_cmnd_dns( itsDns->getDnsId(), name, format, command_routine,
     161                 :            : //                      itsTagId);
     162                 :            :                         (dim_long)this);
     163                 :          0 :                 ENABLE_AST
     164                 :            : //              itsDns->addServiceId(itsId);
     165                 :          0 :                 DimServer::start(itsDns);
     166                 :            :         }
     167                 :          0 : }
     168                 :            : 
     169                 :            : extern "C" {
     170                 :            : /*
     171                 :            : static void timeout_rout(DimRpc *t)
     172                 :            : {
     173                 :            :         sleep(t->itsTimeout);
     174                 :            :         t->itsKilled = 1;
     175                 :            : }
     176                 :            : */
     177                 :          0 : static void rpcin_routine( void *tagp, void *buf, int *size)
     178                 :            : {
     179                 :          0 :         time_t tt1 = 0, tt2 = 0;
     180                 :            : 
     181                 :            : //      int *tag = (int *)tagp;
     182                 :            : //      int id = *tag;
     183                 :            :         DimRpc *t;
     184                 :            :         int tout, clientId, ids[2];
     185                 :            : //      long tid;
     186                 :            : 
     187                 :            : //      t = (DimRpc *)id_get_ptr(id, SRC_DIS);
     188                 :          0 :         t = *(DimRpc **)tagp;
     189                 :          0 :         t->itsDataIn = buf;
     190                 :          0 :         t->itsSizeIn = *size;
     191                 :          0 :         clientId = dis_get_conn_id();
     192                 :          0 :         tout = dis_get_timeout(t->itsIdOut, clientId);
     193                 :          0 :         t->itsTimeout = tout;
     194                 :            : //      tid = 0;
     195                 :          0 :         if(tout > 0)
     196                 :            :         {
     197                 :          0 :                 tt1 = time((time_t *)0);
     198                 :          0 :                 t->itsKilled = 0;
     199                 :            : //              dtq_start_timer(t->itsTimeout,(void(*)(void *))timeout_rout,(void *)t);
     200                 :            : //              tid = dim_start_thread((void(*)(void *))timeout_rout,(void *)t);
     201                 :            :         }
     202                 :          0 :         DimCore::inCallback = 2;
     203                 :          0 :         t->rpcHandler();
     204                 :          0 :         DimCore::inCallback = 0;
     205                 :          0 :         t->itsDataIn = 0;
     206                 :          0 :         t->itsSizeIn = 0;
     207                 :          0 :         if(tout > 0)
     208                 :            :         {
     209                 :          0 :                 tt2 = time((time_t *)0);
     210                 :          0 :                 if((tt2 - tt1) > tout)
     211                 :          0 :                         t->itsKilled = 1;
     212                 :            :         }
     213                 :          0 :         if(!t->itsKilled)
     214                 :            :         {
     215                 :            : //              if(tid)
     216                 :            : //              {
     217                 :            : //                      dtq_stop_timer((void *)t);
     218                 :            : //                      dim_stop_thread(tid);
     219                 :            : //              }
     220                 :          0 :                 ids[0] = clientId;
     221                 :          0 :                 ids[1] = 0;
     222                 :          0 :                 dis_selective_update_service(t->itsIdOut, ids);
     223                 :            :         }
     224                 :          0 : }
     225                 :            : 
     226                 :            : }
     227                 :            : 
     228                 :            : extern "C" {
     229                 :          0 : static void rpcout_routine( void *tagp, void **buf, int *size, int *first_time)
     230                 :            : {
     231                 :            : //      int *tag = (int *)tagp;
     232                 :            : //      int id = *tag;
     233                 :            :         DimRpc *t;
     234                 :            : 
     235                 :            :         if(first_time){}
     236                 :            : //      t = (DimRpc *)id_get_ptr(id, SRC_DIS);
     237                 :          0 :         t = *(DimRpc**)tagp;
     238                 :          0 :         *buf = t->itsDataOut;
     239                 :          0 :         *size = t->itsSizeOut;
     240                 :          0 : }
     241                 :            : }
     242                 :            : 
     243                 :          0 : void DimRpc::declareIt(char *name, char *formatin, char *formatout, DimServerDns *dns)
     244                 :            : {
     245                 :            : //      itsTagId = 0;
     246                 :          0 :         itsIdIn = 0;
     247                 :          0 :         itsIdOut = 0;
     248                 :          0 :         itsDns = dns;
     249                 :          0 :         itsName = new char[(int)strlen(name)+1];
     250                 :          0 :         strcpy( itsName, name);
     251                 :          0 :         itsNameIn = new char[(int)strlen(name)+1+10];
     252                 :          0 :         strcpy( itsNameIn, name);
     253                 :          0 :         strcat(itsNameIn,(char *)"/RpcIn");
     254                 :          0 :         itsNameOut = new char[(int)strlen(name)+1+10];
     255                 :          0 :         strcpy( itsNameOut, name);
     256                 :          0 :         strcat(itsNameOut,(char *)"/RpcOut");
     257                 :          0 :         itsDataOut = new char[1];
     258                 :          0 :         itsDataOutSize = itsSizeOut = 1;
     259                 :          0 :         itsKilled = 0;
     260                 :          0 :         itsTimeout = 0;
     261                 :            : 
     262                 :            : //      itsTagId = id_get((void *)this, SRC_DIS);
     263                 :          0 :         dis_init();
     264                 :          0 :         if(!itsDns)
     265                 :            :         {
     266                 :          0 :                 DISABLE_AST
     267                 :          0 :                 itsIdIn = dis_add_cmnd( itsNameIn, formatin,
     268                 :            : //                      rpcin_routine, itsTagId);
     269                 :            :                         rpcin_routine, (dim_long)this);
     270                 :          0 :                 itsIdOut = dis_add_service( itsNameOut, formatout, 0,0,
     271                 :            : //                      rpcout_routine, itsTagId);
     272                 :            :                         rpcout_routine, (dim_long)this);
     273                 :          0 :                 ENABLE_AST
     274                 :          0 :                 DimServer::start();
     275                 :            :         }
     276                 :            :         else
     277                 :            :         {
     278                 :          0 :                 DISABLE_AST
     279                 :          0 :                 itsIdIn = dis_add_cmnd_dns( itsDns->getDnsId(), itsNameIn, formatin,
     280                 :            : //                      rpcin_routine, itsTagId);
     281                 :            :                         rpcin_routine, (dim_long)this);
     282                 :          0 :                 itsIdOut = dis_add_service_dns( itsDns->getDnsId(), itsNameOut, formatout, 0,0,
     283                 :            : //                      rpcout_routine, itsTagId);
     284                 :            :                         rpcout_routine, (dim_long)this);
     285                 :          0 :                 ENABLE_AST
     286                 :            : //              itsDns->addServiceId(itsIdIn);
     287                 :            : //              itsDns->addServiceId(itsIdOut);
     288                 :          0 :                 DimServer::start(itsDns);
     289                 :            :         }
     290                 :          0 : }
     291                 :            : 
     292                 :          0 : void DimRpc::storeIt(const void *data, int size)
     293                 :            : {
     294                 :          0 :         DISABLE_AST
     295                 :          0 :         if(!itsIdIn)
     296                 :            :         {
     297                 :          0 :                 ENABLE_AST
     298                 :          0 :                 return;
     299                 :            :         }
     300                 :          0 :         if(!itsDataOutSize)
     301                 :            :         {
     302                 :          0 :                 itsDataOut = new char[size];
     303                 :          0 :                 itsDataOutSize = size;
     304                 :            :         }
     305                 :          0 :         else if(itsDataOutSize < size)
     306                 :            :         {
     307                 :          0 :                 delete[] (char *)itsDataOut;
     308                 :          0 :                 itsDataOut = new char[size];
     309                 :          0 :                 itsDataOutSize = size;
     310                 :            :         }
     311                 :          0 :         memcpy(itsDataOut, data, (size_t)size);
     312                 :          0 :         itsSizeOut = size;
     313                 :          0 :         ENABLE_AST
     314                 :            : }
     315                 :            : 
     316                 :            : extern "C" {
     317                 :            : static void client_exit_user_routine(int*);
     318                 :            : static void exit_user_routine(int*);
     319                 :            : static void srv_error_user_routine(int, int, char*);
     320                 :            : }
     321                 :            : 
     322                 :          0 : DimServerDns::DimServerDns(const char *node)
     323                 :            : {
     324                 :          0 :         init(node, 0);
     325                 :          0 : }
     326                 :            : 
     327                 :          0 : DimServerDns::DimServerDns(const char *node, int port)
     328                 :            : {
     329                 :          0 :         init(node, port);
     330                 :          0 : }
     331                 :            : 
     332                 :          0 : DimServerDns::DimServerDns(const char *node, int port, char *name)
     333                 :            : {
     334                 :          0 :         init(node, port);
     335                 :          0 :         DimServer::start(this, name);
     336                 :          0 : }
     337                 :            : 
     338                 :            : #define DisDnsIdBlock 100
     339                 :            : 
     340                 :          0 : void DimServerDns::init(const char *node, int port)
     341                 :            : {
     342                 :            : //      if(!itsNode)
     343                 :            : //      {
     344                 :          0 :                 itsNode = new char[(int)strlen(node)+1];
     345                 :          0 :                 strcpy(itsNode,node);
     346                 :            : //      }
     347                 :          0 :         itsPort = port;
     348                 :          0 :         autoStart = 1;
     349                 :          0 :         itsName = 0;
     350                 :          0 :         itsServiceIdList = new int[DisDnsIdBlock];
     351                 :          0 :         itsServiceIdListSize = DisDnsIdBlock;
     352                 :          0 :         itsNServiceIds = 0;
     353                 :            : //      itsNServices = 0;
     354                 :          0 :         itsDnsId = DimServer::addDns(node, port);
     355                 :          0 : }
     356                 :            : 
     357                 :          0 : void DimServerDns::addServiceId(int id)
     358                 :            : {
     359                 :            :         int *tmp;
     360                 :            : 
     361                 :          0 :         DISABLE_AST
     362                 :          0 :         if((itsNServiceIds + 2) > itsServiceIdListSize)
     363                 :            :         {
     364                 :          0 :                 tmp = new int[itsServiceIdListSize + DisDnsIdBlock];
     365                 :          0 :                 memcpy(tmp, itsServiceIdList, (size_t)itsServiceIdListSize*sizeof(int));
     366                 :          0 :                 delete itsServiceIdList;
     367                 :          0 :                 itsServiceIdList = tmp;
     368                 :          0 :                 itsServiceIdListSize += DisDnsIdBlock;
     369                 :            :         }
     370                 :          0 :         itsServiceIdList[itsNServiceIds] = id;
     371                 :          0 :         itsServiceIdList[itsNServiceIds+1] = 0;
     372                 :          0 :         itsNServiceIds++;
     373                 :          0 :         ENABLE_AST
     374                 :          0 : }
     375                 :            : 
     376                 :          0 : int *DimServerDns::getServiceIdList()
     377                 :            : {
     378                 :            :         int *list;
     379                 :          0 :         if(itsNServiceIds)
     380                 :          0 :                 list = itsServiceIdList;
     381                 :            :         else
     382                 :          0 :                 list = 0;
     383                 :          0 :         itsNServiceIds = 0;
     384                 :          0 :         return list;
     385                 :            : }
     386                 :            : 
     387                 :          0 : DimServerDns::~DimServerDns()
     388                 :            : {
     389                 :          0 :         if(itsName)
     390                 :            :         {
     391                 :          0 :                 DimServer::stop(this);
     392                 :            : //              if(itsName)
     393                 :            : //                      delete[] itsName;
     394                 :            :         }
     395                 :            : //      if(itsNode)
     396                 :          0 :                 delete[] itsNode;
     397                 :          0 : }
     398                 :            : 
     399                 :          0 : dim_long DimServerDns::getDnsId()
     400                 :            : {
     401                 :          0 :         return itsDnsId;
     402                 :            : }
     403                 :            : 
     404                 :          0 : void DimServerDns::setName(const char *name)
     405                 :            : {
     406                 :          0 :         if(!itsName)
     407                 :            :         {
     408                 :          0 :                 itsName = new char[(int)strlen(name)+1];
     409                 :          0 :                 strcpy(itsName,name);
     410                 :            :         }
     411                 :          0 : }
     412                 :            : 
     413                 :          0 : void DimServerDns::clearName()
     414                 :            : {
     415                 :          0 :         if(itsName)
     416                 :            :         {
     417                 :          0 :                 delete[] itsName;
     418                 :          0 :                 itsName = 0;
     419                 :            :         }
     420                 :          0 : }
     421                 :            : 
     422                 :          0 : char *DimServerDns::getName()
     423                 :            : {
     424                 :          0 :         return itsName;
     425                 :            : }
     426                 :            : 
     427                 :          0 : void DimServerDns::autoStartOn()
     428                 :            : {
     429                 :          0 :         autoStart = 1;
     430                 :          0 : }
     431                 :            : 
     432                 :          0 : void DimServerDns::autoStartOff()
     433                 :            : {
     434                 :          0 :         autoStart = 0;
     435                 :          0 : }
     436                 :            : 
     437                 :          0 : int DimServerDns::isAutoStart()
     438                 :            : {
     439                 :          0 :         return autoStart;
     440                 :            : }
     441                 :            : 
     442                 :          0 : DimServer::DimServer()
     443                 :            : {
     444                 :          0 :         itsClientExit = this;
     445                 :          0 :         itsExit = this;
     446                 :          0 :         itsSrvError = this;
     447                 :            : //      itsNServices = 0;
     448                 :          0 : }
     449                 :            : 
     450                 :          0 : DimServer::~DimServer()
     451                 :            : {
     452                 :          0 :         if(itsName)
     453                 :            :         {
     454                 :          0 :                 dis_stop_serving();
     455                 :          0 :                 delete[] itsName;
     456                 :            :         }
     457                 :          0 :         if(clientName)
     458                 :          0 :                 delete[] clientName;
     459                 :          0 :         if(dimDnsNode)
     460                 :          0 :                 delete[] dimDnsNode;
     461                 :          0 : }
     462                 :            : 
     463                 :          3 : void DimServer::start(const char *name)
     464                 :            : {
     465                 :          3 :         if(!itsName)
     466                 :            :         {
     467                 :          3 :                 itsName = new char[(int)strlen(name)+1];
     468                 :          3 :                 strcpy(itsName,name);
     469                 :            :         }
     470                 :          3 :         dis_start_serving(itsName);
     471                 :          3 : }
     472                 :            : 
     473                 :          0 : void DimServer::start(DimServerDns *dns, const char *name)
     474                 :            : {
     475                 :            :         dim_long dnsid;
     476                 :            : 
     477                 :          0 :         dis_init();
     478                 :            :         {
     479                 :          0 :         DISABLE_AST
     480                 :          0 :         dns->setName(name);
     481                 :          0 :         dnsid = dns->getDnsId();
     482                 :          0 :         dis_start_serving_dns(dnsid, (char *)name /*, dns->getServiceIdList()*/);
     483                 :          0 :         ENABLE_AST
     484                 :            :         }
     485                 :          0 : }
     486                 :            : /*
     487                 :            : void DimServer::threadHandler()
     488                 :            : {
     489                 :            :         int oldNServices;
     490                 :            : 
     491                 :            :         while(1)
     492                 :            :         {
     493                 :            :                 oldNServices = itsNServices;
     494                 :            :                 usleep(100000);
     495                 :            :                 if(oldNServices == itsNServices)
     496                 :            :                         break;
     497                 :            :         }
     498                 :            : cout << "Starting " << itsNServices << endl;
     499                 :            :         {
     500                 :            :                 DISABLE_AST
     501                 :            :                 dis_start_serving(itsName);
     502                 :            :                 itsNServices = 0;
     503                 :            :                 ENABLE_AST
     504                 :            :         }
     505                 :            : 
     506                 :            : }
     507                 :            : */
     508                 :          3 : void DimServer::start()
     509                 :            : {
     510                 :            : //      itsNServices++;
     511                 :          3 :         if((itsName) && (autoStart))
     512                 :            :         {
     513                 :            : //              DimThread::start();
     514                 :          2 :                 dis_start_serving(itsName);
     515                 :            :         }
     516                 :          3 : }
     517                 :            : 
     518                 :          0 : void DimServer::start(DimServerDns *dns)
     519                 :            : {
     520                 :            :         dim_long dnsid;
     521                 :            :         char *name;
     522                 :            :         int isAuto;
     523                 :            : 
     524                 :          0 :         dis_init();
     525                 :            :         {
     526                 :          0 :         DISABLE_AST
     527                 :            : //      dns->itsNServices++;
     528                 :            : 
     529                 :          0 :         name = dns->getName();
     530                 :          0 :         dnsid = dns->getDnsId();
     531                 :          0 :         isAuto = dns->isAutoStart();
     532                 :          0 :         if((name) && (isAuto))
     533                 :            :         {
     534                 :            : //              DimThread::start();
     535                 :          0 :                 dis_start_serving_dns(dnsid, (char *)name /*, dns->getServiceIdList()*/);
     536                 :            :         }
     537                 :          0 :         ENABLE_AST
     538                 :            :         }
     539                 :          0 : }
     540                 :            : 
     541                 :          4 : void DimServer::stop()
     542                 :            : {
     543                 :          4 :         dis_stop_serving();
     544                 :          4 :         if(itsName)
     545                 :            :         {
     546                 :          3 :                 delete[] itsName;
     547                 :          3 :                 itsName = 0;
     548                 :            :         }
     549                 :          4 : }
     550                 :            : 
     551                 :          0 : void DimServer::stop(DimServerDns *dns)
     552                 :            : {
     553                 :          0 :         dis_stop_serving_dns(dns->getDnsId());
     554                 :          0 :         dns->clearName();
     555                 :          0 : }
     556                 :            : 
     557                 :          0 : void DimServer::autoStartOn()
     558                 :            : {
     559                 :          0 :         autoStart = 1;
     560                 :          0 : }
     561                 :            : 
     562                 :          0 : void DimServer::autoStartOff()
     563                 :            : {
     564                 :          0 :         autoStart = 0;
     565                 :          0 : }
     566                 :            : 
     567                 :          0 : int DimServer::getClientId()
     568                 :            : {
     569                 :          0 :         if(!clientName)
     570                 :          0 :                 clientName = new char[128];
     571                 :          0 :         clientName[0] = '\0';
     572                 :          0 :         return dis_get_client(clientName);
     573                 :            : }
     574                 :            : 
     575                 :          0 : char *DimServer::getClientName()
     576                 :            : {
     577                 :          0 :         if(!clientName)
     578                 :          0 :                 clientName = new char[128];
     579                 :          0 :         clientName[0] = '\0';
     580                 :          0 :         dis_get_client(clientName);
     581                 :          0 :         return(clientName);
     582                 :            : }
     583                 :            : /*
     584                 :            : char *DimServer::getClientServices()
     585                 :            : {
     586                 :            :         int id;
     587                 :            :         if((id = dis_get_conn_id()))
     588                 :            :                 return dis_get_client_services(id);
     589                 :            :         return (char *)0;
     590                 :            : }
     591                 :            : 
     592                 :            : char *DimServer::getClientServices(int clientId)
     593                 :            : {
     594                 :            :         return dis_get_client_services(clientId);
     595                 :            : }
     596                 :            : */
     597                 :          0 : char **DimServer::getClientServices()
     598                 :            : {
     599                 :            :         static TokenString *data = 0;
     600                 :          0 :         int id, len = 0, index = 0;
     601                 :            :         char *services;
     602                 :            :         static char** list = 0;
     603                 :            :         char *sep;
     604                 :            : 
     605                 :          0 :         if(data)
     606                 :            :         {
     607                 :          0 :                 delete data;
     608                 :          0 :                 data = 0;
     609                 :            :         }
     610                 :          0 :         if(list)
     611                 :            :         {
     612                 :          0 :                 delete[] list;
     613                 :          0 :                 list = 0;
     614                 :            :         }
     615                 :          0 :         if((id = dis_get_conn_id()))
     616                 :            :         {
     617                 :          0 :                 services = dis_get_client_services(id);
     618                 :          0 :                 if(services)
     619                 :            :                 {
     620                 :          0 :                         data = new TokenString(services,(char *)"\n");
     621                 :          0 :                         len = data->getNTokens();
     622                 :          0 :                         list = new char*[len];
     623                 :          0 :                         while(data->getToken(list[index]))
     624                 :            :                         {
     625                 :          0 :                                 data->getToken(sep);
     626                 :          0 :                                 index++;
     627                 :            :                         }
     628                 :            :                 }
     629                 :            :         }
     630                 :          0 :         if(!len)
     631                 :          0 :                 list = new char*[1];
     632                 :          0 :         list[index] = 0;
     633                 :          0 :         return list;
     634                 :            : }
     635                 :            : 
     636                 :          0 : void DimServer::setClientExitHandler(int clientId)
     637                 :            : {
     638                 :          0 :         dis_set_client_exit_handler(clientId, 1);
     639                 :          0 : }
     640                 :            : 
     641                 :          0 : void DimServer::clearClientExitHandler(int clientId)
     642                 :            : {
     643                 :          0 :         dis_set_client_exit_handler(clientId, 0);
     644                 :          0 : }
     645                 :            : 
     646                 :          0 : void DimServer::addClientExitHandler(DimClientExitHandler *handler)
     647                 :            : {
     648                 :          0 :         if(handler == 0)
     649                 :            :         {
     650                 :          0 :                 dis_add_client_exit_handler(0);
     651                 :          0 :                 DimServer::itsClientExit = 0;
     652                 :            :         }
     653                 :            :         else
     654                 :            :         {
     655                 :          0 :                 DimServer::itsClientExit = handler;
     656                 :          0 :                 dis_add_client_exit_handler(client_exit_user_routine);
     657                 :            :         }
     658                 :          0 : }
     659                 :            : 
     660                 :          0 : void DimServer::addClientExitHandler()
     661                 :            : {
     662                 :          0 :         DimServer::itsClientExit = this;
     663                 :          0 :         dis_add_client_exit_handler(client_exit_user_routine);
     664                 :          0 : }
     665                 :            : 
     666                 :          0 : void DimServer::addExitHandler(DimExitHandler *handler)
     667                 :            : {
     668                 :          0 :         if(handler == 0)
     669                 :            :         {
     670                 :          0 :                 dis_add_exit_handler(0);
     671                 :          0 :                 DimServer::itsExit = 0;
     672                 :            :         }
     673                 :            :         else
     674                 :            :         {
     675                 :          0 :                 DimServer::itsExit = handler;
     676                 :          0 :                 dis_add_exit_handler(exit_user_routine);
     677                 :            :         }
     678                 :          0 : }
     679                 :            : 
     680                 :          0 : void DimServer::addErrorHandler(DimErrorHandler *handler)
     681                 :            : {
     682                 :          0 :         if(handler == 0)
     683                 :            :         {
     684                 :          0 :                 dis_add_error_handler(0);
     685                 :          0 :                 DimServer::itsSrvError = 0;
     686                 :            :         }
     687                 :            :         else
     688                 :            :         {
     689                 :          0 :                 DimServer::itsSrvError = handler;
     690                 :          0 :                 dis_add_error_handler(srv_error_user_routine);
     691                 :            :         }
     692                 :          0 : }
     693                 :            : 
     694                 :          0 : int DimServer::setDnsNode(const char *node)
     695                 :            : {
     696                 :          0 :         return dis_set_dns_node((char *)node);
     697                 :            : }
     698                 :            : 
     699                 :          0 : int DimServer::setDnsNode(const char *node, int port)
     700                 :            : {
     701                 :          0 :         dis_set_dns_port(port);
     702                 :          0 :         return dis_set_dns_node((char *)node);
     703                 :            : }
     704                 :            : 
     705                 :          0 : dim_long DimServer::addDns(const char *node, int port)
     706                 :            : {
     707                 :          0 :         return dis_add_dns((char *)node, port);
     708                 :            : }
     709                 :          0 : char *DimServer::getDnsNode()
     710                 :            : {
     711                 :          0 :         if(!dimDnsNode)
     712                 :          0 :                 dimDnsNode = new char[256];
     713                 :          0 :         if(dis_get_dns_node(dimDnsNode))
     714                 :          0 :                 return dimDnsNode;
     715                 :            :         else
     716                 :          0 :                 return 0;
     717                 :            : }
     718                 :            : 
     719                 :          0 : int DimServer::getDnsPort()
     720                 :            : {
     721                 :          0 :         return dis_get_dns_port();
     722                 :            : }
     723                 :            : 
     724                 :          0 : void DimServer::setWriteTimeout(int secs)
     725                 :            : {
     726                 :          0 :         dim_set_write_timeout(secs);
     727                 :          0 : }
     728                 :            : 
     729                 :          0 : int DimServer::getWriteTimeout()
     730                 :            : {
     731                 :          0 :         return dim_get_write_timeout();
     732                 :            : }
     733                 :            : 
     734                 :          0 : void DimServer::addExitHandler()
     735                 :            : {
     736                 :          0 :         DimServer::itsExit = this;
     737                 :          0 :         dis_add_exit_handler(exit_user_routine);
     738                 :          0 : }
     739                 :            : 
     740                 :          0 : void DimServer::addErrorHandler()
     741                 :            : {
     742                 :          0 :         DimServer::itsSrvError = this;
     743                 :          0 :         dis_add_error_handler(srv_error_user_routine);
     744                 :          0 : }
     745                 :            : 
     746                 :          0 : int DimServer::inCallback()
     747                 :            : {
     748                 :          0 :         if(DimCore::inCallback)
     749                 :          0 :                 return 1;
     750                 :          0 :         return 0;
     751                 :            : }
     752                 :            : 
     753                 :            : extern "C" {
     754                 :          0 : static void client_exit_user_routine(int *idp)
     755                 :            : {
     756                 :          0 :         int id = *idp;
     757                 :            : 
     758                 :          0 :         id++;
     759                 :          0 :         DimCore::inCallback = 2;
     760                 :          0 :         DimServer::itsClientExit->clientExitHandler();
     761                 :          0 :         DimCore::inCallback = 0;
     762                 :          0 : }
     763                 :            : 
     764                 :          0 : static void exit_user_routine(int *idp)
     765                 :            : {
     766                 :            : //      int id = *idp;
     767                 :            : 
     768                 :            : //      id++;
     769                 :          0 :         DimCore::inCallback = 2;
     770                 :          0 :         DimServer::itsExit->exitHandler(*idp);
     771                 :          0 :         DimCore::inCallback = 0;
     772                 :          0 : }
     773                 :            : 
     774                 :          0 : static void srv_error_user_routine(int severity, int code, char *msg)
     775                 :            : {
     776                 :            : 
     777                 :          0 :         DimCore::inCallback = 2;
     778                 :          0 :         if(DimServer::itsSrvError != 0)
     779                 :          0 :                 DimServer::itsSrvError->errorHandler(severity, code, msg);
     780                 :          0 :         DimCore::inCallback = 0;
     781                 :          0 : }
     782                 :            : 
     783                 :            : }
     784                 :            : 
     785                 :            : 
     786                 :          0 : DimService::DimService()
     787                 :            : {
     788                 :            : //      itsTagId = 0;
     789                 :          0 :         itsId = 0;
     790                 :          0 :         itsName = 0;
     791                 :          0 : }
     792                 :            : 
     793                 :          2 : DimService::DimService(const char *name, int value)
     794                 :            : {
     795                 :          2 :         itsId = 0;
     796                 :          2 :         itsName = 0;
     797                 :          2 :         itsType = DisINT;
     798                 :          2 :         itsDataSize = 0;
     799                 :          2 :         setData(value);
     800                 :          2 :         declareIt((char *)name, (char *)"L", 0, 0);
     801                 :          2 : }
     802                 :            : 
     803                 :          1 : DimService::DimService(const char *name, float value)
     804                 :            : {
     805                 :          1 :         itsId = 0;
     806                 :          1 :         itsName = 0;
     807                 :          1 :         itsType = DisFLOAT;
     808                 :          1 :         itsDataSize = 0;
     809                 :          1 :         setData(value);
     810                 :          1 :         declareIt((char *)name, (char *)"F", 0, 0);
     811                 :          1 : }
     812                 :            : 
     813                 :          0 : DimService::DimService(const char *name, double value)
     814                 :            : {
     815                 :          0 :         itsId = 0;
     816                 :          0 :         itsName = 0;
     817                 :          0 :         itsType = DisDOUBLE;
     818                 :          0 :         itsDataSize = 0;
     819                 :          0 :         setData(value);
     820                 :          0 :         declareIt((char *)name, (char *)"D", 0, 0);
     821                 :          0 : }
     822                 :            : 
     823                 :          0 : DimService::DimService(const char *name, longlong value)
     824                 :            : {
     825                 :          0 :         itsId = 0;
     826                 :          0 :         itsName = 0;
     827                 :          0 :         itsType = DisXLONG;
     828                 :          0 :         itsDataSize = 0;
     829                 :          0 :         setData(value);
     830                 :          0 :         declareIt((char *)name, (char *)"X", 0, 0);
     831                 :          0 : }
     832                 :            : 
     833                 :          0 : DimService::DimService(const char *name, short value)
     834                 :            : {
     835                 :          0 :         itsId = 0;
     836                 :          0 :         itsName = 0;
     837                 :          0 :         itsType = DisSHORT;
     838                 :          0 :         itsDataSize = 0;
     839                 :          0 :         setData(value);
     840                 :          0 :         declareIt((char *)name, (char *)"S", 0, 0);
     841                 :          0 : }
     842                 :            : 
     843                 :          0 : DimService::DimService(const char *name, const char *string)
     844                 :            : {
     845                 :          0 :         itsId = 0;
     846                 :          0 :         itsName = 0;
     847                 :          0 :         itsType = DisSTRING;
     848                 :          0 :         itsDataSize = 0;
     849                 :          0 :         setData(string);
     850                 :          0 :         declareIt((char *)name, (char *)"C", 0, 0);
     851                 :          0 : }
     852                 :            : 
     853                 :          0 : DimService::DimService(const char *name, char *format, const void *structure, int size)
     854                 :            : {
     855                 :          0 :         itsId = 0;
     856                 :          0 :         itsName = 0;
     857                 :          0 :         itsType = DisPOINTER;
     858                 :          0 :         itsDataSize = 0;
     859                 :          0 :         setData(structure, size);
     860                 :          0 :         declareIt((char *)name, (char *)format, 0, 0);
     861                 :          0 : }
     862                 :            : 
     863                 :          0 : DimService::DimService(const char *name, char *format, DimServiceHandler *handler)
     864                 :            : {
     865                 :          0 :         itsId = 0;
     866                 :          0 :         itsName = 0;
     867                 :          0 :         itsData = 0;
     868                 :          0 :         itsSize = 0;
     869                 :          0 :         itsType = DisPOINTER;
     870                 :          0 :         itsDataSize = 0;
     871                 :          0 :         declareIt((char *)name, (char *)format, handler, 0);
     872                 :          0 : }
     873                 :            : 
     874                 :          0 : DimService::DimService(const char *name, const char *format, const void *structure, int size)
     875                 :            : {
     876                 :          0 :         itsId = 0;
     877                 :          0 :         itsName = 0;
     878                 :          0 :         itsType = DisPOINTER;
     879                 :          0 :         itsDataSize = 0;
     880                 :          0 :         setData(structure, size);
     881                 :          0 :         declareIt((char *)name, (char *)format, 0, 0);
     882                 :          0 : }
     883                 :            : 
     884                 :          0 : DimService::DimService(const char *name, const char *format, DimServiceHandler *handler)
     885                 :            : {
     886                 :          0 :         itsId = 0;
     887                 :          0 :         itsName = 0;
     888                 :          0 :         itsData = 0;
     889                 :          0 :         itsSize = 0;
     890                 :          0 :         itsDataSize = 0;
     891                 :          0 :         itsType = DisPOINTER;
     892                 :          0 :         declareIt((char *)name, (char *)format, handler, 0);
     893                 :          0 : }
     894                 :            : 
     895                 :            : // with Dns
     896                 :            : 
     897                 :          0 : DimService::DimService(DimServerDns *dns, const char *name, int value)
     898                 :            : {
     899                 :          0 :         itsId = 0;
     900                 :          0 :         itsName = 0;
     901                 :          0 :         itsType = DisINT;
     902                 :          0 :         itsDataSize = 0;
     903                 :          0 :         setData(value);
     904                 :          0 :         declareIt((char *)name, (char *)"L", 0, dns);
     905                 :          0 : }
     906                 :            : 
     907                 :          0 : DimService::DimService(DimServerDns *dns, const char *name, float value)
     908                 :            : {
     909                 :          0 :         itsId = 0;
     910                 :          0 :         itsName = 0;
     911                 :          0 :         itsType = DisFLOAT;
     912                 :          0 :         itsDataSize = 0;
     913                 :          0 :         setData(value);
     914                 :          0 :         declareIt((char *)name, (char *)"F", 0, dns);
     915                 :          0 : }
     916                 :            : 
     917                 :          0 : DimService::DimService(DimServerDns *dns, const char *name, double value)
     918                 :            : {
     919                 :          0 :         itsId = 0;
     920                 :          0 :         itsName = 0;
     921                 :          0 :         itsType = DisDOUBLE;
     922                 :          0 :         itsDataSize = 0;
     923                 :          0 :         setData(value);
     924                 :          0 :         declareIt((char *)name, (char *)"D", 0, dns);
     925                 :          0 : }
     926                 :            : 
     927                 :          0 : DimService::DimService(DimServerDns *dns, const char *name, longlong value)
     928                 :            : {
     929                 :          0 :         itsId = 0;
     930                 :          0 :         itsName = 0;
     931                 :          0 :         itsType = DisXLONG;
     932                 :          0 :         itsDataSize = 0;
     933                 :          0 :         setData(value);
     934                 :          0 :         declareIt((char *)name, (char *)"X", 0, dns);
     935                 :          0 : }
     936                 :            : 
     937                 :          0 : DimService::DimService(DimServerDns *dns, const char *name, short value)
     938                 :            : {
     939                 :          0 :         itsId = 0;
     940                 :          0 :         itsName = 0;
     941                 :          0 :         itsType = DisSHORT;
     942                 :          0 :         itsDataSize = 0;
     943                 :          0 :         setData(value);
     944                 :          0 :         declareIt((char *)name, (char *)"S", 0, dns);
     945                 :          0 : }
     946                 :            : 
     947                 :          0 : DimService::DimService(DimServerDns *dns, const char *name, const char *string)
     948                 :            : {
     949                 :          0 :         itsId = 0;
     950                 :          0 :         itsName = 0;
     951                 :          0 :         itsType = DisSTRING;
     952                 :          0 :         itsDataSize = 0;
     953                 :          0 :         setData(string);
     954                 :          0 :         declareIt((char *)name, (char *)"C", 0, dns);
     955                 :          0 : }
     956                 :            : 
     957                 :          0 : DimService::DimService(DimServerDns *dns, const char *name, char *format, const void *structure, int size)
     958                 :            : {
     959                 :          0 :         itsId = 0;
     960                 :          0 :         itsName = 0;
     961                 :          0 :         itsType = DisPOINTER;
     962                 :          0 :         itsDataSize = 0;
     963                 :          0 :         setData(structure, size);
     964                 :          0 :         declareIt((char *)name, (char *)format, 0, dns);
     965                 :          0 : }
     966                 :            : 
     967                 :          0 : DimService::DimService(DimServerDns *dns, const char *name, char *format, DimServiceHandler *handler)
     968                 :            : {
     969                 :          0 :         itsId = 0;
     970                 :          0 :         itsName = 0;
     971                 :          0 :         itsData = 0;
     972                 :          0 :         itsSize = 0;
     973                 :          0 :         itsDataSize = 0;
     974                 :          0 :         itsType = DisPOINTER;
     975                 :          0 :         declareIt((char *)name, (char *)format, handler, dns);
     976                 :          0 : }
     977                 :            : 
     978                 :            : 
     979                 :          0 : DimService::DimService(DimServerDns *dns, const char *name, const char *format, const void *structure, int size)
     980                 :            : {
     981                 :          0 :         itsId = 0;
     982                 :          0 :         itsName = 0;
     983                 :          0 :         itsType = DisPOINTER;
     984                 :          0 :         itsDataSize = 0;
     985                 :          0 :         setData(structure, size);
     986                 :          0 :         declareIt((char *)name, (char *)format, 0, dns);
     987                 :          0 : }
     988                 :            : 
     989                 :          0 : DimService::DimService(DimServerDns *dns, const char *name, const char *format, DimServiceHandler *handler)
     990                 :            : {
     991                 :          0 :         itsId = 0;
     992                 :          0 :         itsName = 0;
     993                 :          0 :         itsData = 0;
     994                 :          0 :         itsSize = 0;
     995                 :          0 :         itsType = DisPOINTER;
     996                 :          0 :         itsDataSize = 0;
     997                 :          0 :         declareIt((char *)name, (char *)format, handler, dns);
     998                 :          0 : }
     999                 :            : 
    1000                 :            : 
    1001                 :          3 : DimService::~DimService()
    1002                 :            : {
    1003                 :          3 :         int ret = 0;
    1004                 :            :         void *dnsp;
    1005                 :            : 
    1006                 :          3 :         DISABLE_AST
    1007                 :          3 :         if(itsName)
    1008                 :          3 :                 delete[] itsName;
    1009                 :          3 :         if(itsDataSize)
    1010                 :          3 :                 delete[] (char *)itsData;
    1011                 :            : //      if(itsTagId)
    1012                 :            : //              id_free(itsTagId, SRC_DIS);
    1013                 :          3 :         if(itsId)
    1014                 :          3 :                 ret = do_dis_remove_service( itsId, 0, &dnsp );
    1015                 :          3 :         itsId = 0;
    1016                 :          3 :         ENABLE_AST
    1017                 :          3 :         if(ret == -1)
    1018                 :            :         {
    1019                 :          3 :                 do_dis_stop_serving_dns(dnsp);
    1020                 :            :         }
    1021                 :          3 : }
    1022                 :            : 
    1023                 :          0 : int DimService::updateService()
    1024                 :            : {
    1025                 :          0 :         if(!itsId)
    1026                 :          0 :                 return 0;
    1027                 :          0 :         return dis_update_service( itsId );
    1028                 :            : }
    1029                 :            : 
    1030                 :          2 : int DimService::updateService( int value )
    1031                 :            : {
    1032                 :          2 :         if(!itsId)
    1033                 :          0 :                 return 0;
    1034                 :          2 :         if( itsType == DisINT)
    1035                 :            :         {
    1036                 :          2 :                 storeIt(&value, sizeof(int));
    1037                 :          2 :                 return dis_update_service( itsId );
    1038                 :            :         }
    1039                 :          0 :         return -1;
    1040                 :            : }
    1041                 :            : 
    1042                 :          2 : int DimService::updateService( float value )
    1043                 :            : {
    1044                 :          2 :         if(!itsId)
    1045                 :          0 :                 return 0;
    1046                 :          2 :         if( itsType == DisFLOAT) {
    1047                 :          2 :                 storeIt(&value, sizeof(float));
    1048                 :          2 :                 return dis_update_service( itsId );
    1049                 :            :         }
    1050                 :          0 :         return -1;
    1051                 :            : }
    1052                 :            : 
    1053                 :          0 : int DimService::updateService( double value )
    1054                 :            : {
    1055                 :          0 :         if(!itsId)
    1056                 :          0 :                 return 0;
    1057                 :          0 :         if( itsType == DisDOUBLE) {
    1058                 :          0 :                 storeIt(&value, sizeof(double));
    1059                 :          0 :                 return dis_update_service( itsId );
    1060                 :            :         }
    1061                 :          0 :         return -1;
    1062                 :            : }
    1063                 :            : 
    1064                 :          0 : int DimService::updateService( longlong value )
    1065                 :            : {
    1066                 :          0 :         if(!itsId)
    1067                 :          0 :                 return 0;
    1068                 :          0 :         if( itsType == DisXLONG)
    1069                 :            :         {
    1070                 :          0 :                 storeIt(&value, sizeof(longlong));
    1071                 :          0 :                 return dis_update_service( itsId );
    1072                 :            :         }
    1073                 :          0 :         return -1;
    1074                 :            : }
    1075                 :            : 
    1076                 :          0 : int DimService::updateService( short value )
    1077                 :            : {
    1078                 :          0 :         if(!itsId)
    1079                 :          0 :                 return 0;
    1080                 :          0 :         if( itsType == DisSHORT)
    1081                 :            :         {
    1082                 :          0 :                 storeIt(&value, sizeof(short));
    1083                 :          0 :                 return dis_update_service( itsId );
    1084                 :            :         }
    1085                 :          0 :         return -1;
    1086                 :            : }
    1087                 :            : 
    1088                 :          0 : int DimService::updateService( const char *string )
    1089                 :            : {
    1090                 :          0 :         if(!itsId)
    1091                 :          0 :                 return 0;
    1092                 :          0 :         if( itsType == DisSTRING)
    1093                 :            :         {
    1094                 :          0 :                 storeIt(string, strlen(string) + 1);
    1095                 :          0 :                 return dis_update_service( itsId );
    1096                 :            :         }
    1097                 :          0 :         return -1;
    1098                 :            : }
    1099                 :            : 
    1100                 :          0 : int DimService::updateService( const void *structure, int size )
    1101                 :            : {
    1102                 :          0 :         if(!itsId)
    1103                 :          0 :                 return 0;
    1104                 :          0 :         if( itsType == DisPOINTER)
    1105                 :            :         {
    1106                 :          0 :                 storeIt(structure, size);
    1107                 :          0 :                 return dis_update_service( itsId );
    1108                 :            :         }
    1109                 :          0 :         return -1;
    1110                 :            : }
    1111                 :            : 
    1112                 :          0 : int DimService::selectiveUpdateService(int *cids)
    1113                 :            : {
    1114                 :          0 :         if(!itsId)
    1115                 :          0 :                 return 0;
    1116                 :          0 :         if( cids == 0)
    1117                 :            :         {
    1118                 :            :                 int ids[2];
    1119                 :          0 :                 ids[0] = DimServer::getClientId();
    1120                 :          0 :                 ids[1] = 0;
    1121                 :          0 :                 return dis_selective_update_service( itsId, ids );
    1122                 :            :         }
    1123                 :          0 :         return dis_selective_update_service( itsId, cids );
    1124                 :            : }
    1125                 :            : 
    1126                 :          0 : int DimService::selectiveUpdateService( int value, int *cids)
    1127                 :            : {
    1128                 :          0 :         if(!itsId)
    1129                 :          0 :                 return 0;
    1130                 :          0 :         if( itsType == DisINT)
    1131                 :            :         {
    1132                 :          0 :                 storeIt(&value, sizeof(int));
    1133                 :          0 :                 if( cids == 0)
    1134                 :            :                 {
    1135                 :            :                         int ids[2];
    1136                 :          0 :                         ids[0] = DimServer::getClientId();
    1137                 :          0 :                         ids[1] = 0;
    1138                 :          0 :                         return dis_selective_update_service( itsId, ids );
    1139                 :            :                 }
    1140                 :          0 :                 return dis_selective_update_service( itsId, cids );
    1141                 :            :         }
    1142                 :          0 :         return -1;
    1143                 :            : }
    1144                 :            : 
    1145                 :          0 : int DimService::selectiveUpdateService( float value, int *cids )
    1146                 :            : {
    1147                 :          0 :         if(!itsId)
    1148                 :          0 :                 return 0;
    1149                 :          0 :         if( itsType == DisFLOAT)
    1150                 :            :         {
    1151                 :          0 :                 storeIt(&value, sizeof(float));
    1152                 :          0 :                 if( cids == 0)
    1153                 :            :                 {
    1154                 :            :                         int ids[2];
    1155                 :          0 :                         ids[0] = DimServer::getClientId();
    1156                 :          0 :                         ids[1] = 0;
    1157                 :          0 :                         return dis_selective_update_service( itsId, ids );
    1158                 :            :                 }
    1159                 :          0 :                 return dis_selective_update_service( itsId, cids );
    1160                 :            :         }
    1161                 :          0 :         return -1;
    1162                 :            : }
    1163                 :            : 
    1164                 :          0 : int DimService::selectiveUpdateService( double value, int *cids )
    1165                 :            : {
    1166                 :          0 :         if(!itsId)
    1167                 :          0 :                 return 0;
    1168                 :          0 :         if( itsType == DisDOUBLE)
    1169                 :            :         {
    1170                 :          0 :                 storeIt(&value, sizeof(double));
    1171                 :          0 :                 if( cids == 0)
    1172                 :            :                 {
    1173                 :            :                         int ids[2];
    1174                 :          0 :                         ids[0] = DimServer::getClientId();
    1175                 :          0 :                         ids[1] = 0;
    1176                 :          0 :                         return dis_selective_update_service( itsId, ids );
    1177                 :            :                 }
    1178                 :          0 :                 return dis_selective_update_service( itsId, cids );
    1179                 :            :         }
    1180                 :          0 :         return -1;
    1181                 :            : }
    1182                 :            : 
    1183                 :          0 : int DimService::selectiveUpdateService( longlong value, int *cids )
    1184                 :            : {
    1185                 :          0 :         if(!itsId)
    1186                 :          0 :                 return 0;
    1187                 :          0 :         if( itsType == DisXLONG)
    1188                 :            :         {
    1189                 :          0 :                 storeIt(&value, sizeof(longlong));
    1190                 :          0 :                 if( cids == 0)
    1191                 :            :                 {
    1192                 :            :                         int ids[2];
    1193                 :          0 :                         ids[0] = DimServer::getClientId();
    1194                 :          0 :                         ids[1] = 0;
    1195                 :          0 :                         return dis_selective_update_service( itsId, ids );
    1196                 :            :                 }
    1197                 :          0 :                 return dis_selective_update_service( itsId, cids );
    1198                 :            :         }
    1199                 :          0 :         return -1;
    1200                 :            : }
    1201                 :            : 
    1202                 :          0 : int DimService::selectiveUpdateService( short value, int *cids )
    1203                 :            : {
    1204                 :          0 :         if(!itsId)
    1205                 :          0 :                 return 0;
    1206                 :          0 :         if( itsType == DisSHORT)
    1207                 :            :         {
    1208                 :          0 :                 storeIt(&value, sizeof(short));
    1209                 :          0 :                 if( cids == 0)
    1210                 :            :                 {
    1211                 :            :                         int ids[2];
    1212                 :          0 :                         ids[0] = DimServer::getClientId();
    1213                 :          0 :                         ids[1] = 0;
    1214                 :          0 :                         return dis_selective_update_service( itsId, ids );
    1215                 :            :                 }
    1216                 :          0 :                 return dis_selective_update_service( itsId, cids );
    1217                 :            :         }
    1218                 :          0 :         return -1;
    1219                 :            : }
    1220                 :            : 
    1221                 :          0 : int DimService::selectiveUpdateService( const char *string, int *cids )
    1222                 :            : {
    1223                 :          0 :         if(!itsId)
    1224                 :          0 :                 return 0;
    1225                 :          0 :         if( itsType == DisSTRING)
    1226                 :            :         {
    1227                 :          0 :                 storeIt(string, strlen(string) + 1);
    1228                 :          0 :                 if( cids == 0)
    1229                 :            :                 {
    1230                 :            :                         int ids[2];
    1231                 :          0 :                         ids[0] = DimServer::getClientId();
    1232                 :          0 :                         ids[1] = 0;
    1233                 :          0 :                         return dis_selective_update_service( itsId, ids );
    1234                 :            :                 }
    1235                 :          0 :                 return dis_selective_update_service( itsId, cids );
    1236                 :            :         }
    1237                 :          0 :         return -1;
    1238                 :            : }
    1239                 :            : 
    1240                 :          0 : int DimService::selectiveUpdateService( const void *structure, int size, int *cids )
    1241                 :            : {
    1242                 :          0 :         if(!itsId)
    1243                 :          0 :                 return 0;
    1244                 :          0 :         if( itsType == DisPOINTER)
    1245                 :            :         {
    1246                 :          0 :                 storeIt(structure, size);
    1247                 :          0 :                 if( cids == 0)
    1248                 :            :                 {
    1249                 :            :                         int ids[2];
    1250                 :          0 :                         ids[0] = DimServer::getClientId();
    1251                 :          0 :                         ids[1] = 0;
    1252                 :          0 :                         return dis_selective_update_service( itsId, ids );
    1253                 :            :                 }
    1254                 :          0 :                 return dis_selective_update_service( itsId, cids );
    1255                 :            :         }
    1256                 :          0 :         return -1;
    1257                 :            : }
    1258                 :            : 
    1259                 :          0 : void DimService::setQuality(int quality)
    1260                 :            : {
    1261                 :          0 :         if(!itsId)
    1262                 :          0 :                 return;
    1263                 :          0 :         dis_set_quality( itsId, quality );
    1264                 :            : }
    1265                 :            : 
    1266                 :          0 : void DimService::setTimestamp(int secs, int millisecs)
    1267                 :            : {
    1268                 :          0 :         if(!itsId)
    1269                 :          0 :                 return;
    1270                 :          0 :         dis_set_timestamp( itsId, secs, millisecs );
    1271                 :            : }
    1272                 :            : 
    1273                 :          0 : char *DimService::getName()
    1274                 :            : {
    1275                 :          0 :         return itsName;
    1276                 :            : }
    1277                 :            : 
    1278                 :          0 : int DimService::getTimeout(int clientId)
    1279                 :            : {
    1280                 :          0 :         return dis_get_timeout(itsId, clientId);
    1281                 :            : }
    1282                 :            : 
    1283                 :          0 : int DimService::getNClients()
    1284                 :            : {
    1285                 :          0 :         return dis_get_n_clients( itsId );
    1286                 :            : }
    1287                 :            : 
    1288                 :            : 
    1289                 :          0 : CmndInfo::CmndInfo(void *data, int datasize, int tsecs, int tmillisecs)
    1290                 :            : {
    1291                 :          0 :         itsData = new char[datasize];
    1292                 :          0 :         itsDataSize = datasize;
    1293                 :          0 :         secs = tsecs;
    1294                 :          0 :         millisecs = tmillisecs;
    1295                 :          0 :         memcpy(itsData, data, (size_t)datasize);
    1296                 :          0 : }
    1297                 :            : 
    1298                 :          0 : CmndInfo::~CmndInfo()
    1299                 :            : {
    1300                 :          0 :         delete[] (char *)itsData;
    1301                 :          0 : }
    1302                 :            : 
    1303                 :            : 
    1304                 :          0 : DimCommand::DimCommand(const char *name, char *format)
    1305                 :            : {
    1306                 :          0 :         declareIt( (char *)name, (char *)format, 0, 0);
    1307                 :          0 : }
    1308                 :            : 
    1309                 :          0 : DimCommand::DimCommand(const char *name, char *format, DimCommandHandler *handler)
    1310                 :            : {
    1311                 :          0 :         declareIt( (char *)name, (char *)format, handler, 0);
    1312                 :          0 : }
    1313                 :            : 
    1314                 :          0 : DimCommand::DimCommand(DimServerDns *dns, const char *name, char *format)
    1315                 :            : {
    1316                 :          0 :         declareIt( (char *)name, (char *)format, 0, dns);
    1317                 :          0 : }
    1318                 :            : 
    1319                 :          0 : DimCommand::DimCommand(DimServerDns *dns, const char *name, char *format, DimCommandHandler *handler)
    1320                 :            : {
    1321                 :          0 :         declareIt( (char *)name, (char *)format, handler, dns);
    1322                 :          0 : }
    1323                 :            : 
    1324                 :            : 
    1325                 :          0 : DimCommand::DimCommand(const char *name, const char *format)
    1326                 :            : {
    1327                 :          0 :         declareIt( (char *)name, (char *)format, 0, 0);
    1328                 :          0 : }
    1329                 :            : 
    1330                 :          0 : DimCommand::DimCommand(const char *name, const char *format, DimCommandHandler *handler)
    1331                 :            : {
    1332                 :          0 :         declareIt( (char *)name, (char *)format, handler, 0);
    1333                 :          0 : }
    1334                 :            : 
    1335                 :          0 : DimCommand::DimCommand(DimServerDns *dns, const char *name, const char *format)
    1336                 :            : {
    1337                 :          0 :         declareIt( (char *)name, (char *)format, 0, dns);
    1338                 :          0 : }
    1339                 :            : 
    1340                 :          0 : DimCommand::DimCommand(DimServerDns *dns, const char *name, const char *format, DimCommandHandler *handler)
    1341                 :            : {
    1342                 :          0 :         declareIt( (char *)name, (char *)format, handler, dns);
    1343                 :          0 : }
    1344                 :            : 
    1345                 :          0 : int DimCommand::getNext()
    1346                 :            : {
    1347                 :            :         CmndInfo *cmndptr;
    1348                 :          0 :         if(currCmnd)
    1349                 :            :         {
    1350                 :          0 :                 delete currCmnd;
    1351                 :          0 :                 currCmnd = 0;
    1352                 :          0 :                 itsData = 0;
    1353                 :          0 :                 itsSize = 0;
    1354                 :            :         }
    1355                 :          0 :         if ((cmndptr = (CmndInfo *)itsCmndList.removeHead()))
    1356                 :            :         {
    1357                 :          0 :                 currCmnd = cmndptr;
    1358                 :          0 :                 itsData = currCmnd->itsData;
    1359                 :          0 :                 itsSize = currCmnd->itsDataSize;
    1360                 :          0 :                 secs = currCmnd->secs;
    1361                 :          0 :                 millisecs = currCmnd->millisecs;
    1362                 :          0 :                 return(1);
    1363                 :            :         }
    1364                 :          0 :         return(0);
    1365                 :            : }
    1366                 :            : 
    1367                 :          0 : int DimCommand::hasNext()
    1368                 :            : {
    1369                 :          0 :         if ((CmndInfo *)itsCmndList.getHead())
    1370                 :            :         {
    1371                 :          0 :                 return(1);
    1372                 :            :         }
    1373                 :          0 :         return(0);
    1374                 :            : }
    1375                 :            : 
    1376                 :          0 : void *DimCommand::getData()
    1377                 :            : {
    1378                 :          0 :         return itsData;
    1379                 :            : }
    1380                 :            : 
    1381                 :          0 : int DimCommand::getInt()
    1382                 :            : {
    1383                 :          0 :         return *(int *)itsData;
    1384                 :            : }
    1385                 :            : 
    1386                 :          0 : float DimCommand::getFloat()
    1387                 :            : {
    1388                 :          0 :         return *(float *)itsData;
    1389                 :            : }
    1390                 :            : 
    1391                 :          0 : double DimCommand::getDouble()
    1392                 :            : {
    1393                 :          0 :         return *(double *)itsData;
    1394                 :            : }
    1395                 :            : 
    1396                 :          0 : longlong DimCommand::getLonglong()
    1397                 :            : {
    1398                 :          0 :         return *(longlong *)itsData;
    1399                 :            : }
    1400                 :            : 
    1401                 :          0 : short DimCommand::getShort()
    1402                 :            : {
    1403                 :          0 :         return *(short *)itsData;
    1404                 :            : }
    1405                 :            : 
    1406                 :          0 : char *DimCommand::getString()
    1407                 :            : {
    1408                 :          0 :         return (char *)itsData;
    1409                 :            : }
    1410                 :            : 
    1411                 :          0 : int DimCommand::getSize()
    1412                 :            : {
    1413                 :          0 :         return itsSize;
    1414                 :            : }
    1415                 :            : 
    1416                 :          0 : char *DimCommand::getFormat()
    1417                 :            : {
    1418                 :          0 :         return itsFormat;
    1419                 :            : }
    1420                 :            : 
    1421                 :          0 : int DimCommand::getTimestamp()
    1422                 :            : {
    1423                 :            : 
    1424                 :          0 :         if(secs == 0)
    1425                 :            :         {
    1426                 :          0 :                 DISABLE_AST
    1427                 :          0 :                 if(itsId)
    1428                 :          0 :                         dis_get_timestamp(itsId, &secs, &millisecs);
    1429                 :          0 :                 ENABLE_AST
    1430                 :            :         }
    1431                 :          0 :         return(secs);
    1432                 :            : }
    1433                 :            : 
    1434                 :          0 : int DimCommand::getTimestampMillisecs()
    1435                 :            : {
    1436                 :          0 :         return(millisecs);
    1437                 :            : }
    1438                 :            : 
    1439                 :          0 : void DimCommand::commandHandler()
    1440                 :            : {
    1441                 :            :         CmndInfo *cmndptr;
    1442                 :            :         int tsecs, tmillisecs;
    1443                 :            : 
    1444                 :          0 :         tsecs = getTimestamp();
    1445                 :          0 :         tmillisecs = getTimestampMillisecs();
    1446                 :          0 :         cmndptr = new CmndInfo(getData(), getSize(), tsecs, tmillisecs);
    1447                 :          0 :         itsCmndList.add(cmndptr);
    1448                 :          0 : }
    1449                 :            : 
    1450                 :          0 : char *DimCommand::getName()
    1451                 :            : {
    1452                 :          0 :         return itsName;
    1453                 :            : }
    1454                 :            : 
    1455                 :          0 : DimCommand::~DimCommand()
    1456                 :            : {
    1457                 :          0 :         int ret = 0;
    1458                 :            :         void *dnsp;
    1459                 :            : 
    1460                 :          0 :         DISABLE_AST
    1461                 :          0 :         delete[] itsName;
    1462                 :          0 :         delete[] itsFormat;
    1463                 :            : //      if(itsTagId)
    1464                 :            : //              id_free(itsTagId, SRC_DIS);
    1465                 :          0 :         if(itsId)
    1466                 :          0 :                 ret = do_dis_remove_service( itsId, 0, &dnsp );
    1467                 :          0 :         itsId = 0;
    1468                 :          0 :         ENABLE_AST
    1469                 :          0 :         if(ret == -1)
    1470                 :            :         {
    1471                 :          0 :                 do_dis_stop_serving_dns(dnsp);
    1472                 :            :         }
    1473                 :          0 : }
    1474                 :            : 
    1475                 :          0 : DimRpc::DimRpc()
    1476                 :            : {
    1477                 :          0 : }
    1478                 :            : 
    1479                 :          0 : DimRpc::DimRpc(const char *name, const char *formatin, const char *formatout)
    1480                 :            : {
    1481                 :          0 :         declareIt( (char *)name, (char *)formatin, (char *)formatout, 0);
    1482                 :          0 : }
    1483                 :            : 
    1484                 :          0 : DimRpc::DimRpc(DimServerDns *dns, const char *name, const char *formatin, const char *formatout)
    1485                 :            : {
    1486                 :          0 :         declareIt( (char *)name, (char *)formatin, (char *)formatout, dns);
    1487                 :          0 : }
    1488                 :            : 
    1489                 :          0 : DimRpc::~DimRpc()
    1490                 :            : {
    1491                 :          0 :         int ret = 0;
    1492                 :            :         void *dnsp;
    1493                 :            : 
    1494                 :          0 :         DISABLE_AST
    1495                 :          0 :         delete[] itsName;
    1496                 :          0 :         delete[] itsNameIn;
    1497                 :          0 :         delete[] itsNameOut;
    1498                 :            : //      if(itsTagId)
    1499                 :            : //              id_free(itsTagId, SRC_DIS);
    1500                 :          0 :         if(itsIdIn)
    1501                 :          0 :                 ret = do_dis_remove_service( itsIdIn, 0, &dnsp );
    1502                 :          0 :         if(itsIdOut)
    1503                 :          0 :                 ret = do_dis_remove_service( itsIdOut, 0, &dnsp );
    1504                 :          0 :         itsIdIn = 0;
    1505                 :          0 :         itsIdOut = 0;
    1506                 :          0 :         ENABLE_AST
    1507                 :          0 :         if(ret == -1)
    1508                 :            :         {
    1509                 :          0 :                 do_dis_stop_serving_dns(dnsp);
    1510                 :            :         }
    1511                 :          0 : }
    1512                 :            : 
    1513                 :          0 : void *DimRpc::getData()
    1514                 :            : {
    1515                 :          0 :         return itsDataIn;
    1516                 :            : }
    1517                 :            : 
    1518                 :          0 : int DimRpc::getInt()
    1519                 :            : {
    1520                 :          0 :         return *(int *)itsDataIn;
    1521                 :            : }
    1522                 :            : 
    1523                 :          0 : float DimRpc::getFloat()
    1524                 :            : {
    1525                 :          0 :         return *(float *)itsDataIn;
    1526                 :            : }
    1527                 :            : 
    1528                 :          0 : double DimRpc::getDouble()
    1529                 :            : {
    1530                 :          0 :         return *(double *)itsDataIn;
    1531                 :            : }
    1532                 :            : 
    1533                 :          0 : longlong DimRpc::getLonglong()
    1534                 :            : {
    1535                 :          0 :         return *(longlong *)itsDataIn;
    1536                 :            : }
    1537                 :            : 
    1538                 :          0 : short DimRpc::getShort()
    1539                 :            : {
    1540                 :          0 :         return *(short *)itsDataIn;
    1541                 :            : }
    1542                 :            : 
    1543                 :          0 : char *DimRpc::getString()
    1544                 :            : {
    1545                 :          0 :         return (char *)itsDataIn;
    1546                 :            : }
    1547                 :            : 
    1548                 :          0 : int DimRpc::getSize()
    1549                 :            : {
    1550                 :          0 :         return itsSizeIn;
    1551                 :            : }
    1552                 :            : 
    1553                 :          0 : void DimRpc::setData(const void *data, int size)
    1554                 :            : {
    1555                 :          0 :         storeIt(data, size);
    1556                 :          0 : }
    1557                 :            : 
    1558                 :          0 : void DimRpc::setData(int data)
    1559                 :            : {
    1560                 :          0 :         storeIt(&data, sizeof(int));
    1561                 :          0 : }
    1562                 :            : 
    1563                 :          0 : void DimRpc::setData(float data)
    1564                 :            : {
    1565                 :          0 :         storeIt(&data, sizeof(float));
    1566                 :          0 : }
    1567                 :            : 
    1568                 :          0 : void DimRpc::setData(double data)
    1569                 :            : {
    1570                 :          0 :         storeIt(&data, sizeof(double));
    1571                 :          0 : }
    1572                 :            : 
    1573                 :          0 : void DimRpc::setData(longlong data)
    1574                 :            : {
    1575                 :          0 :         storeIt(&data, sizeof(longlong));
    1576                 :          0 : }
    1577                 :            : 
    1578                 :          0 : void DimRpc::setData(short data)
    1579                 :            : {
    1580                 :          0 :         storeIt(&data, sizeof(short));
    1581                 :          0 : }
    1582                 :            : 
    1583                 :          0 : void DimRpc::setData(const char *data)
    1584                 :            : {
    1585                 :          0 :         storeIt(data, (int) strlen(data) + 1);
    1586                 :          0 : }
    1587                 :            : 
    1588                 :          0 : char *DimRpc::getName()
    1589                 :            : {
    1590                 :          0 :         return itsName;
    1591                 :            : }

Generated by: LCOV version 1.14