예제 #1
0
/*
 * Z family protocols shutdown.
 *
 * Z transport and Z network layer will be shutdown.
 *
 * @param [in] Communication_p Communication module context.
 *
 * @retval  E_SUCCESS                   After successful execution.
 * @retval  E_INVALID_INPUT_PARAMETERS  Invalid input parameter.
 */
ErrorCode_e Z_Family_Shutdown(Communication_t *Communication_p)
{
    ErrorCode_e ReturnValue = E_INVALID_INPUT_PARAMETERS;

    if (NULL == Communication_p) {
        return E_INVALID_INPUT_PARAMETERS;
    }

    ReturnValue = Z_Transport_Shutdown(Communication_p);
    VERIFY_CONDITION(E_SUCCESS == ReturnValue);

    ReturnValue = Z_Network_Shutdown(Communication_p);
    VERIFY_CONDITION(E_SUCCESS == ReturnValue);
    free(Communication_p->FamilyContext_p);
    Communication_p->FamilyContext_p = NULL;

    if (NULL != Communication_p->BackupCommBuffer_p) {
        free(Communication_p->BackupCommBuffer_p);
        Communication_p->BackupCommBuffer_p = NULL;
    }

    Communication_p->BackupCommBufferSize = 0;
    Communication_p->CurrentFamilyHash = HASH_NONE;

ErrorExit:

    return ReturnValue;
}
예제 #2
0
 Application& Application::addComponent(ApplicationComponent *component)
 {
     VERIFY_CONDITION((find(_componentsToInit.begin(), _componentsToInit.end(), component) == _componentsToInit.end() && !_inited));
     _componentsToInit.push_back(component);
     
     return *this;
 }
예제 #3
0
/*
 * Z family protocols initialization.
 *
 * Z transport and Z network layer will be initialized.
 *
 * @param [in] Communication_p Communication module context.
 *
 * @retval  E_SUCCESS                   After successful execution.
 * @retval  E_INVALID_INPUT_PARAMETERS  Invalid input parameter.
 */
ErrorCode_e Z_Family_Init(Communication_t *Communication_p)
{
    ErrorCode_e ReturnValue = E_INVALID_INPUT_PARAMETERS;

    if (NULL == Communication_p) {
        return E_INVALID_INPUT_PARAMETERS;
    }

    if (NULL != Communication_p->BackupCommBuffer_p) {
        free(Communication_p->BackupCommBuffer_p);
        Communication_p->BackupCommBuffer_p = NULL;
    }

    Communication_p->BackupCommBufferSize = 0;

    Communication_p->FamilyContext_p = malloc(sizeof(Z_FamilyContext_t));

    if (NULL == Communication_p->FamilyContext_p) {
        return E_ALLOCATE_FAILED;
    }

    Communication_p->CurrentFamilyHash = HASH_NONE;
    Z_NETWORK(Communication_p)->Inbound.StopTransfer = FALSE;

    ReturnValue = Z_Transport_Initialize(Communication_p);
    VERIFY_CONDITION(E_SUCCESS == ReturnValue);

    ReturnValue = Z_Network_Initialize(Communication_p);

ErrorExit:
    return ReturnValue;
}
예제 #4
0
 void Application::run()
 {
     VERIFY_CONDITION(_inited); // TODO msg application wasn't inited
     _running = true;
     
     while (_running)
     {
         for (auto & component : _initedComponents)
         {
             if (component->running())
             {
                 component->update();
             }
         }
     }
 }
예제 #5
0
 void Application::terminate()
 {
     VERIFY_CONDITION(_inited); // TODO msg application wasn't inited
     std::cout << "Info: Application's termination stared!" << std::endl;
     
     for (auto & component : _initedComponents)
     {
         component->terminate();
         
         std::cout << "Info: \"" << component->getName() << "\" component terminanted!" << std::endl;
     }
     
     _initedComponents.clear();
     
     std::cout << "Info: Application's termination finished! (success)" << std::endl;
 }
예제 #6
0
 bool Application::init()
 {
     VERIFY_CONDITION(!_inited); // TODO msg application already inited
     std::cout << "Info: Application's initialization stared!" << std::endl;
     
     for (auto & component : _componentsToInit)
     {
         if (!component->init())
         {
             std::cout << "Error: Failed to initialize \"" << component->getName() << "\" component!" << std::endl;
             
             for (auto & component : _initedComponents)
             {
                 component->terminate();
                 
                 std::cout << "Info: \"" << component->getName() << "\" component terminanted!" << std::endl;
             }
             
             _initedComponents.clear();
             
             std::cout << "Info: Application's initialization finished! (fail)" << std::endl;
             
             return false;
         }
         else
         {
             std::cout << "Info: \"" << component->getName() << "\" component intiliazed!" << std::endl;
             
             _initedComponents.push_front(component);
         }
     }
     
     _componentsToInit.clear();
     _inited = true;
     
     std::cout << "Info: Application's initialization finished! (success)" << std::endl;
     
     return true;
 }
예제 #7
0
int data()
{
    static FILE* file = fopen("/Users/toxa/Workplace/Projects/NES/sprites/mario.chr", "rb");
    
    VERIFY_CONDITION(file);
    
    char c;
    int count = 8192 / 2;
    int count2 = 8;
    int count3 = 0;
    bool newLine = false;
    do
    {
        c = fgetc(file);
        std::bitset<8> x(c);
        c = fgetc(file);
        std::bitset<8> y(c);
        
        for (int i = 0; i < 8; ++i)
        {
            std::bitset<2> temp;
            temp[0] = x[i];
            temp[1] = y[i];
            
            switch (temp.to_ulong()) {
                case 0:
                    std::cout << "__";
                    break;
                    
                case 1:
                    std::cout << "OO";
                    break;
                    
                case 2:
                    std::cout << "BB";
                    break;
                    
                case 3:
                    std::cout << "XX";
                    break;
            }
            
        }
        
//        fseek (file, 0, SEEK_END);   // non-portable
//        int size=ftell (file);
//        
//        std::cout << size;
        
//        std::cout << x.to_string();
        
        count2--;
        if (count2 == 0)
        {
            count3++;
            std::cout << (count3) << std::endl;
            std::cout << std::endl;
            count2 = 8;
        }
        
        std::cout << std::endl;
        
        
        newLine = !newLine;
        count--;
    }
    while (count != 0);
    
    return 10;
}
예제 #8
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{

  try
    {
      // Initialize the ORB first.
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc,
                         argv,
                         "POAManagerFactoryTest");

      if (parse_args (argc, argv) != 0)
        return 1;

      // Obtain the RootPOA.
      CORBA::Object_var obj =
        orb->resolve_initial_references ("RootPOA");

      // Narrow to POA.
      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (obj.in ());

      if (verbose)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT("Obtain PoaManagerFactory reference: ")));
      pretest = fail;

      // Obtain the POAManagerFactory.
      PortableServer::POAManagerFactory_var poa_manager_factory
        = root_poa->the_POAManagerFactory ();

      VERIFY_CONDITION (!CORBA::is_nil(poa_manager_factory.in()));
      if (verbose)
        ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
                    (pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed")));
      if (CORBA::is_nil(poa_manager_factory.in()))
        return 1;

      CORBA::PolicyList policies (0);
      policies.length (0);

      if (verbose)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT("Create a POAManager: ")));
      pretest = fail;

      // Explicitly create a POAManager - "POAManager1" .
      PortableServer::POAManager_var poa_manager_1
        = poa_manager_factory->create_POAManager ("POAManager1",
                                                  policies);

      VERIFY_CONDITION (!CORBA::is_nil(poa_manager_1.in()));
      if (verbose)
        ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
                    (pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed")));
      if (CORBA::is_nil(poa_manager_1.in()))
        return 1;

      // Creating a POAManager with an exiting POAManager name raises exception.
      if (verbose)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT("Prevent duplicated POAManagers: ")));
      pretest = fail;
      CORBA::Boolean got_expected_exception = false;
      try
      {
        PortableServer::POAManager_var poa_manager
         = poa_manager_factory->create_POAManager ("POAManager1",
                                                   policies);
      }
      catch (const PortableServer::POAManagerFactory::ManagerAlreadyExists& )
      {
        got_expected_exception = true;
      }

      VERIFY_CONDITION (got_expected_exception);
      if (verbose)
        ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
                    (pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed")));

      if (! got_expected_exception)
        return 1;

      {
        if (verbose)
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT("Implicitly create a POAManagers: ")));
        pretest = fail;
        // Implicitly create a POAManager instance which has an automatically
        // assigned name.
        PortableServer::POA_var child_poa =
        root_poa->create_POA ("childPOA2",
                              PortableServer::POAManager::_nil (),
                              policies);

        PortableServer::POAManager_var poa_manager_2
          = child_poa->the_POAManager ();

        VERIFY_CONDITION (!CORBA::is_nil(poa_manager_2.in()));
        if (verbose)
          ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
                      (pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed")));

        if (CORBA::is_nil(poa_manager_2.in()))
          return 1;

        CORBA::String_var poa_manager_2_name
          = poa_manager_2->get_id ();
        if (verbose)
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT("Implicitly created POAManager's ID: [%C]\n"),
                      poa_manager_2_name.in()));

        if (ACE_OS::strlen(poa_manager_2_name.in()) == 0)
          return 1;

        if (verbose)
          ACE_DEBUG ((LM_DEBUG, ACE_TEXT("List POAManagers: ")));
        pretest = fail;

        PortableServer::POAManagerFactory::POAManagerSeq_var managers
          = poa_manager_factory->list ();

        VERIFY_CONDITION (managers->length () == 3);
        if (verbose)
          ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
                      (pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed")));

        PortableServer::POAManager_var root_poa_manager
          = root_poa->the_POAManager();

        for (CORBA::ULong i = 0; i < managers->length(); ++i)
        {
          CORBA::String_var name = managers[i]->get_id ();
          if (verbose)
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT("Validate listed POAManager [%C]: "),
                        name.in()));
          pretest = fail;

          const PortableServer::POAManager_ptr tmp_pm = managers[i];
          if ((ACE_OS::strcmp (name.in (), "RootPOAManager") == 0
            && tmp_pm == root_poa_manager.in ())
            || (ACE_OS::strcmp (name.in (), "POAManager1") == 0
            && tmp_pm == poa_manager_1.in ())
            || (ACE_OS::strcmp (name.in (), poa_manager_2_name.in ()) == 0
            && tmp_pm == poa_manager_2.in ()))
            {
              if (verbose)
                ACE_DEBUG ((LM_DEBUG, ACE_TEXT("passed\n")));
              continue;
            }
          else
            {
              if (verbose)
                ACE_DEBUG ((LM_DEBUG, ACE_TEXT("failed\n")));
              fail++;
            }
        }
      }

      {
        // Find a specific POAManager.
        if (verbose)
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT("Find a POAManager: ")));
        pretest = fail;

        PortableServer::POAManager_var manager
          = poa_manager_factory->find ("POAManager1");

        CORBA::String_var name = manager->get_id ();

        VERIFY_CONDITION ((ACE_OS::strcmp (name.in (), "POAManager1") == 0
                 && manager.in () == poa_manager_1.in ()));

        if (verbose)
          ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("%s\n"),
                      (pretest == fail) ? ACE_TEXT ("passed") : ACE_TEXT ("failed")));
      }

      // Create a child poa that associates with the explicitly
      // created POAManager.
      if (verbose)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT("Create A POA with explicit  POAManager: ")));
      pretest = fail;
      PortableServer::POA_var child_poa =
        root_poa->create_POA ("childPOA",
                              poa_manager_1.in (),
                              policies);

      poa_manager_1->activate ();

      root_poa->destroy (1, 1);

      orb->destroy ();

      if (verbose)
        ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("passed\n")));
    }
  catch (const CORBA::Exception& ex)
    {
      fail++;
      if (verbose)
        ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("failed\n")));
      ex._tao_print_exception ("Exception caught");
    }

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT("POAManagerFactory %s\n"),
              (pretest == fail) ? ACE_TEXT ("succeeded") : ACE_TEXT ("failed")));

  return 0;
}