docs: function Controller (gateway, svcopts, svc) {
      // Add DebugTool to log messages
      this.uid    = "Controller://" + svcopts.info + "/" + svcopts.adapter + ":" + svcopts.port;
      this.debug  = gateway.opts.services.debug || gateway.debug;
      this.svcopts= svcopts;
      this.gateway= gateway;
      this.svc    = svc;
  
      // take care or default adapter svcopts
      if (svcopts.mindist  === undefined) this.svcopts.mindist =200; // in m
      if (svcopts.maxtime  === undefined) this.svcopts.maxtime =3600;// in s == 1h
      if (svcopts.maxspeed === undefined) this.svcopts.maxspeed=100;  // in 100m/s=~400km/h
      if (svcopts.debug    === undefined) this.svcopts.debug   =this.debug;
      if (svcopts.debug    === undefined) this.svcopts.debug   =this.debug;
      if (svcopts.hostname === undefined) this.svcopts.hostname='localhost';
      if (svcopts.timeout  === undefined) this.svcopts.timeout=60;
      if (svcopts.maxerrors=== undefined) this.svcopts.maxerrors=2;
      // load device adapter as described within svcopts option from user application
      try {
          var  adapter  =  require(availableAdapters [svcopts.adapter]);  
      } catch (err) {
          this.Debug (0, 'Invalid adapter name : [%s] Error=%s', svcopts.adapter, err);
          console.log ("gateway aborted");
          process.exit();
      }
      this.adapter           =  new adapter (this);
      
      // Depending on adapter's control type logic for handling tcp socket change
      switch (this.adapter.control) {
      case 'tcpsock':
          // in tcpsock mode gateway uses tcp session to track a given device.
          // Each time a new client raises, it creates a new TcpConnect and attaches
          // a SockClient object to it. Device handler is then called from SockClient.
          this.tcpServer           = net.createServer(TcpConnect);
          this.tcpServer.uid       = "TcpServer://" + svcopts.adapter + ':' + svcopts.port;
          this.tcpServer.evtname   = 'data';
          this.tcpServer.controller= this;
          this.tcpServer.adapter   = this.adapter;
          this.tcpServer.count     = 0;   // number of active tcp clients 
          this.tcpServer.listen(svcopts.port, TcpSvrListenOk); 
          this.tcpServer.on('error', TcpSvrListenFx);
          break;
      case 'websock':
          // websocket start like an http connection and endup as a TcpConnect
          var adapter = this.adapter;
          var webSockOpts=
              {port         :svcopts.port
              ,verifyClient :function(info, callback){WebSockVerify(adapter, info, callback)}
          }
          this.wsServer=new webSocket (webSockOpts);
          this.wsServer.uid = "websock://" + svcopts.adapter + ':' + svcopts.port;
          this.wsServer.controller = this;
          this.wsServer.adapter   = this.adapter;
          this.wsServer.evtname   = 'message';
          this.wsServer.on('listening', TcpSvrListenOk);
          this.wsServer.on('connection',TcpConnect);
          break;
      case 'http':
          // in http mode, gateway cannot use tcp session to handle device, and deviceID
          // has to be present in each http/post. HttpRequest function calls
          // device adapter specific functions directly. The adapter creates
          // an HttpClient object based on devID present within each http/post request.
          this.tcpServer           = http.createServer(HttpRequest);
          this.tcpServer.uid       = "HttpServer://" + svcopts.adapter + ':' + svcopts.port;
          this.tcpServer.controller= this;
          this.tcpServer.adapter   = this.adapter;
          this.tcpServer.svcopts   = svcopts;
          this.tcpServer.listen(svcopts.port, TcpSvrListenOk); 
          this.tcpServer.on('error', TcpSvrListenFx);
          break;
      case 'tcpfeed':
          // in tcpfeed, gateway is a client of a remote server. And only one svcopts is
          // attached to a given instance of an adapter. Connected being unique it
          // is directly handled at adapter level.
          this.tcpClient           =  net.createConnection(svcopts.remport, svcopts.hostname);
          this.tcpClient.uid       = "TcpClient://" + svcopts.adapter + ':' + svcopts.remport;
          this.tcpClient.controller = this;
          this.tcpClient.adapter   = this.adapter;
          this.tcpClient.svcopts   = svcopts;
          this.tcpClient.on('connect', TcpClientConnect);
          this.tcpClient.on('data'   , TcpClientData); 
          this.tcpClient.on('end'    , TcpClientEnd);
          this.tcpClient.on('error'  , TcpClientError);
          break;
      default:
          this.Debug (0,"Hoops Invalid control class [%s] adapter [%s] class", adapter.control, availableAdapters [svcopts.adapter]);
      }
  }