Esempio n. 1
0
   INT32 _pmdController::init ()
   {
      INT32 rc = SDB_OK ;
      pmdOptionsCB *pOptCB = pmdGetOptionCB() ;
      UINT16 port = 0 ;
      CHAR fapModuleName[ FAP_MODULE_NAME_SIZE + 1 ] = { 0 } ;

      if ( pOptCB->hasField( FAP_OPTION_NAME ) )
      {
         pOptCB->getFieldStr( FAP_OPTION_NAME, fapModuleName,
                              FAP_MODULE_NAME_SIZE, "" ) ;
         rc = initForeignModule( fapModuleName ) ;
         PD_RC_CHECK( rc, PDERROR, "Failed to init fap module, rc: %d", rc ) ;
      }

      // 1. create tcp listerner
      port = pOptCB->getServicePort() ;
      // memory will be freed in fini
      _pTcpListener = SDB_OSS_NEW ossSocket( port ) ;
      if ( !_pTcpListener )
      {
         PD_LOG( PDERROR, "Failed to alloc socket" ) ;
         rc = SDB_OOM ;
         goto error ;
      }
      rc = _pTcpListener->initSocket() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to init tcp listener socket[%d], "
                   "rc: %d", port, rc ) ;

      rc = _pTcpListener->bind_listen() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to bind tcp listener socket[%d], "
                   "rc: %d", port, rc ) ;
      PD_LOG( PDEVENT, "Listerning on port[%d]", port ) ;

      // 2. create http listerner
      rc = ossGetPort( pOptCB->getRestService(), port ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to get port by service name: %s, "
                   "rc: %d", pOptCB->getRestService(), rc ) ;
      _pHttpListener = SDB_OSS_NEW ossSocket( port ) ;
      if ( !_pHttpListener )
      {
         PD_LOG( PDERROR, "Failed to alloc socket" ) ;
         rc = SDB_OOM ;
         goto error ;
      }
      rc = _pHttpListener->initSocket() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to init http listener socket[%d], "
                   "rc: %d", port, rc ) ;
      rc = _pHttpListener->bind_listen() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to bind http listerner socket[%d], "
                   "rc: %d", port, rc ) ;
      PD_LOG( PDEVENT, "Http Listerning on port[%d]", port ) ;

   done:
      return rc ;
   error:
      if ( SDB_NETWORK == rc )
      {
         rc = SDB_NET_CANNOT_LISTEN ;
      }
      goto done ;
   }
Esempio n. 2
0
   INT32 _pmdController::init ()
   {
      INT32 rc = SDB_OK ;
      pmdOptionsCB *pOptCB = pmdGetOptionCB() ;
      UINT16 port = 0 ;
      UINT16 protocolPort = 0 ;


      port = pOptCB->getServicePort() ;
      _pTcpListener = SDB_OSS_NEW ossSocket( port ) ;
      if ( !_pTcpListener )
      {
         PD_LOG( PDERROR, "Failed to alloc socket" ) ;
         rc = SDB_OOM ;
         goto error ;
      }
      rc = _pTcpListener->initSocket() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to init tcp listener socket[%d], "
                   "rc: %d", port, rc ) ;

      rc = _pTcpListener->bind_listen() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to bind tcp listener socket[%d], "
                   "rc: %d", port, rc ) ;
      PD_LOG( PDEVENT, "Listerning on port[%d]", port ) ;

      rc = ossGetPort( pOptCB->getRestService(), port ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to get port by service name: %s, "
                   "rc: %d", pOptCB->getRestService(), rc ) ;
      _pHttpListener = SDB_OSS_NEW ossSocket( port ) ;
      if ( !_pHttpListener )
      {
         PD_LOG( PDERROR, "Failed to alloc socket" ) ;
         rc = SDB_OOM ;
         goto error ;
      }
      rc = _pHttpListener->initSocket() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to init http listener socket[%d], "
                   "rc: %d", port, rc ) ;
      rc = _pHttpListener->bind_listen() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to bind http listerner socket[%d], "
                   "rc: %d", port, rc ) ;
      PD_LOG( PDEVENT, "Http Listerning on port[%d]", port ) ;

      if ( FALSE )
      {
         protocolPort = ossAtoi( _protocol->getServiceName() ) ;
         _pMongoListener = SDB_OSS_NEW ossSocket( protocolPort ) ;
         if ( !_pMongoListener )
         {
            PD_LOG( PDERROR, "Failed to alloc socket" ) ;
            rc = SDB_OOM ;
            goto error ;
         }
         rc = _pMongoListener->initSocket() ;
         PD_RC_CHECK( rc, PDERROR, "Failed to init FAP listener socket[%d], "
                      "rc: %d", protocolPort, rc ) ;

         rc = _pMongoListener->bind_listen() ;
         PD_RC_CHECK( rc, PDERROR, "Failed to bind FAP listener socket[%d], "
                      "rc: %d", protocolPort, rc ) ;
         PD_LOG( PDEVENT, "Listerning on port[%d]", protocolPort ) ;
      }

   done:
      return rc ;
   error:
      goto done ;
   }
Esempio n. 3
0
   INT32 _pmdController::initForeignModule( const CHAR *moduleName )
   {
      INT32 rc = SDB_OK ;
      UINT16 protocolPort = 0 ;
      CHAR rootPath[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ;
      CHAR path[ OSS_MAX_PATHSIZE + 1 ] = { 0 } ;

      if (  NULL == moduleName || '\0' == moduleName[ 0 ] )
      {
         goto done ;
      }

      _fapMongo = SDB_OSS_NEW pmdModuleLoader() ;
      if ( NULL == _fapMongo )
      {
         PD_LOG( PDERROR, "Failed to alloc foreign access protocol module" ) ;
         rc = SDB_OOM ;
         goto error ;
      }
      rc = ossGetEWD( rootPath, OSS_MAX_PATHSIZE ) ;
      if ( rc )
      {
         ossPrintf ( "Failed to get excutable file's working "
                     "directory"OSS_NEWLINE ) ;
         goto error ;
      }
      rc = utilBuildFullPath( rootPath, FAP_MODULE_PATH,
                              OSS_MAX_PATHSIZE, path );
      if ( rc )
      {
         ossPrintf( "Failed to build module path: %d"OSS_NEWLINE, rc ) ;
         goto error ;
      }
      rc = _fapMongo->load( moduleName, path ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to load module: %s, path: %s"
                   " rc: %d", moduleName, FAP_MODULE_PATH, rc ) ;
      rc = _fapMongo->create( _protocol ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to create protocol service" ) ;

      SDB_ASSERT( _protocol, "Foreign access protocol can not be NULL" ) ;
      rc = _protocol->init( pmdGetKRCB() ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to init protocol" ) ;

      // memory will be freed in fini
      protocolPort = ossAtoi( _protocol->getServiceName() ) ;
      _pMongoListener = SDB_OSS_NEW ossSocket( protocolPort ) ;
      if ( !_pMongoListener )
      {
         PD_LOG( PDERROR, "Failed to alloc socket" ) ;
         rc = SDB_OOM ;
         goto error ;
      }
      rc = _pMongoListener->initSocket() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to init FAP listener socket[%d], "
                   "rc: %d", protocolPort, rc ) ;

      rc = _pMongoListener->bind_listen() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to bind FAP listener socket[%d], "
                   "rc: %d", protocolPort, rc ) ;
      PD_LOG( PDEVENT, "Listerning on port[%d]", protocolPort ) ;

   done:
      return rc ;
   error:
      goto done ;
   }