Пример #1
0
bool CBattleFieldLayer::init()
{
    do
    {
        BREAK_IF_FAILED(CTouchesLayer::init());
        
        Director *pDirector = Director::getInstance();
        pDirector->setDepthTest(true);
        
        setTouchEnabled(true);
        
        initListener();
        
        loadConfig();

        BREAK_IF_FAILED(CBkgLayerBase::initBkgLayerBase(BATCHNODE_LIST, BACKGROUND_MAP_NAME, TILE_MAP_NAME));
        setGamePanelLayer(CGamePanelLayer::create());
        addChild(m_pGamePanelLayer, Z_ORDER_GAME_PANEL);

        BREAK_IF_FAILED(EFFECT_MANAGER->init(getBkgGrd()));
        
        BREAK_IF_FAILED(BF_MANAGER->init());

        loadFormation();
        scheduleUpdate();

        return true;
    } while (false);
    
    return false;
}
Пример #2
0
/**
 * A simple sync send / listen example 
 */
bool sendAndListenTest01()
{
  TML_INT32 iErr = TML_SUCCESS; // API return value
  /////////////////////////////////////////////////////////////////////////
  // TML_CORE_HANDLE to receive commands / messages 
  TML_CORE_HANDLE coreListenerHandle = TML_HANDLE_TYPE_NULL;
  /////////////////////////////////////////////////////////////////////////
  // TML_CORE_HANDLE to send commands / messages 
  TML_CORE_HANDLE coreSenderHandle = TML_HANDLE_TYPE_NULL;
  /////////////////////////////////////////////////////////////////////////
  // TML_COMMAND_HANDLE Command / message HANDLE (internal represented by SIDEX data)
  TML_COMMAND_HANDLE cmdMsg  = TML_HANDLE_TYPE_NULL;
  /////////////////////////////////////////////////////////////////////////
  // Listener initialisation:
  iErr = initListener(&coreListenerHandle);
  /////////////////////////////////////////////////////////////////////////
  // Command / message creation:
  if (TML_SUCCESS == iErr)
    iErr = createCmd4711(&cmdMsg, false);
  /////////////////////////////////////////////////////////////////////////
  // TML_CORE_HANDLE to send commands / messages 
  if (TML_SUCCESS == iErr)
    iErr = tml_Core_Open(&coreSenderHandle, 0);

  /////////////////////////////////////////////////////////////////////////
  // send a loop of command / messages
  for (int i = 0; i < 10 && TML_SUCCESS == iErr; ++i){
#ifdef TML_UNICODE
    fwprintf (stderr, L"Sending sync command 4711 to %ls -->\n", DESTINATION_HOST_IP);
#else// TML_UNICODE
    printf ("Sending sync command 4711 to %s -->\n", DESTINATION_HOST_IP);
#endif// TML_UNICODE
    iErr = tml_Send_SyncMessage(coreSenderHandle, cmdMsg, IO_PROFILE, DESTINATION_HOST_IP, IO_PORT, 10000);
    if (TML_SUCCESS == iErr){
#ifdef TML_UNICODE
      fwprintf (stderr, L"Sending sync command 4711 (PROFILE2) to %ls -->\n", DESTINATION_HOST_IP);
#else// TML_UNICODE
      printf ("Sending sync command 4711 to %s -->\n", DESTINATION_HOST_IP);
#endif// TML_UNICODE
    iErr = tml_Send_SyncMessage(coreSenderHandle, cmdMsg, IO_PROFILE2, DESTINATION_HOST_IP, IO_PORT, 10000);
      }
  }
  ///////////////////////////////////////////////////////////////////////
  // Free the instance of Command / message HANDLE:
  if (TML_HANDLE_TYPE_NULL != cmdMsg)
    tml_Cmd_Free(&cmdMsg);
  ///////////////////////////////////////////////////////////////////////
  // Free the instances of TMLCore:
  if (TML_HANDLE_TYPE_NULL != coreSenderHandle)
    tml_Core_Close(&coreSenderHandle);
  if (TML_HANDLE_TYPE_NULL != coreListenerHandle)
    tml_Core_Close(&coreListenerHandle);

  ///////////////////////////////////////////////////////////////////////
  // Errorhandling:
  if (TML_SUCCESS != iErr)
    printf ("sendAndListenTest01 / error happened - Code = %d\n", iErr);
  return true;
}
Пример #3
0
int main(int argc, const char * argv[]) {
    
    int port;
    
    port = openSerialPort("/dev/tty....");
    initConnection(port);
    initListener();
    
    return 0;
}
Пример #4
0
int main(int argc, char **argv) {
  int socket;

  daemonize(USER);

  if ((socket = initListener(NULL, PORT)) == -1)
    exit(1);

  return startService(&netcat, socket);
}
Пример #5
0
int dispatch_config(struct event_base* event_base) {
  if (config->listeners) {
    struct listener* l = config->listeners;
    while (l) {
      if (initListener(event_base, l))
        return 1;
      l = l->next;
    }
  }
  return 0;
};
	Listener::Listener(const Ogre::String& name) :
		Ogre::MovableObject(name),
		mGain(1.0),
		mPosition(Ogre::Vector3::ZERO),
		mDirection(Ogre::Vector3::NEGATIVE_UNIT_Z),
		mVelocity(Ogre::Vector3::ZERO),
		mUp(Ogre::Vector3::UNIT_Y),
		mDerivedPosition(Ogre::Vector3::ZERO),
		mDerivedDirection(Ogre::Vector3::NEGATIVE_UNIT_Z)
	{
		mParentNode = NULL;
		initListener();
	}
	Listener::Listener() :
		mGain(1.0),
		mPosition(Ogre::Vector3::ZERO),
		mDirection(Ogre::Vector3::NEGATIVE_UNIT_Z),
		mVelocity(Ogre::Vector3::ZERO),
		mUp(Ogre::Vector3::UNIT_Y),
		mDerivedPosition(Ogre::Vector3::ZERO),
		mDerivedDirection(Ogre::Vector3::NEGATIVE_UNIT_Z)
	{
		mParentNode = NULL;
		mLocalTransformDirty = false;
		initListener();
	}
bool KeyboardButton::init(const Config &config)
{
	uninit();

	if (config.key == EventKeyboard::KeyCode::KEY_NONE)
	{
		return false;
	}

	m_key = config.key;
	m_is_pressed = false;

	setGood(initListener());
	return *this;
}
Пример #9
0
void Client::initServer(const std::string& name, const sf::IpAddress& address, sf::Uint16 port)
{
	// If client is already connected to a server, do not try to re-connect it.
	// We talk here about a socket connexion, not the authentication.
	if(_isConnected)
		throw UnableToConnectException("already connected.");
	_name = shrinkName(name);
	_serverAddress = address;
	_serverPort = port;
	// if connection does not work, don't go further
	if(_socket.connect(address, port) != sf::Socket::Done)
		throw UnableToConnectException("unable to connect to server on port " + std::to_string(port) + ".");
	if(!_userTerminal.hasKnownTerminal())
		std::cout << "Warning: as no known terminal has been found, chat is disabled" << std::endl;
	else
		initListener();  // creates the new thread which listens for entring chat conenctions
	sf::sleep(SOCKET_TIME_SLEEP);  // wait a quarter second to let the listening thread init the port
}
SoundManager::SoundManager()
{
	m_soundDevice	= NULL;
	m_masterVoice	= NULL;
	m_music			= NULL;
	m_masterVolume	= 0;
	m_left			= 0;
	m_right			= 0;


	/************************************************************************/
	/* Don't looks much to the world but here is where all the magic is done*/
	/************************************************************************/
	init();

	initListener();

	m_masterVoice->GetVolume(&m_masterVolume);
}
Пример #11
0
/**
 * A simple listener example 
 */
bool listenerTest01()
{
  TML_INT32 iErr = TML_SUCCESS; // API return value
  /////////////////////////////////////////////////////////////////////////
  // TML_CORE_HANDLE to receive commands / messages 
  TML_CORE_HANDLE coreHandle = TML_HANDLE_TYPE_NULL;

  iErr = initListener(&coreHandle);
  /////////////////////////////////////////////////////////////////////////
  // loop until the input of "exit"
  if (TML_SUCCESS == iErr)
    waitUntilExitInput((char*)"listenerTest01");
  ///////////////////////////////////////////////////////////////////////
  // Free the instance of TMLCore:
  if (TML_HANDLE_TYPE_NULL != coreHandle)
    tml_Core_Close(&coreHandle);
  if (TML_SUCCESS != iErr)
    printf ("listenerTest01 / error happened - Code = %d\n", iErr);
  return true;
}
Пример #12
0
bool tlsTest()
{
  TML_BOOL bEncrypted = TML_FALSE;
  TML_BOOL bAccepted = TML_FALSE;
#ifdef TML_UNICODE
  wchar_t* sErrormessage;
#else// TML_UNICODE
  char* sErrormessage;
#endif// TML_UNICODE  

  TML_INT32 iErr = TML_SUCCESS; // API return value
  /////////////////////////////////////////////////////////////////////////
  // TML_CORE_HANDLE to receive commands / messages 
  TML_CORE_HANDLE coreListenerHandle = TML_HANDLE_TYPE_NULL;
  /////////////////////////////////////////////////////////////////////////
  // TML_CORE_HANDLE to send commands / messages 
  TML_CORE_HANDLE coreSenderHandle = TML_HANDLE_TYPE_NULL;
  /////////////////////////////////////////////////////////////////////////
  // TML_COMMAND_HANDLE Command / message HANDLE (internal represented by SIDEX data)
  TML_COMMAND_HANDLE cmdMsg  = TML_HANDLE_TYPE_NULL;
  /////////////////////////////////////////////////////////////////////////
  // Listener initialisation:
  iErr = initListener(&coreListenerHandle);
  /////////////////////////////////////////////////////////////////////////
  // Allow to configure if the provided tml core will accept TLS incoming connections
  if (TML_SUCCESS == iErr)
  {
    iErr = tml_Tls_Core_AcceptNegotiation(coreListenerHandle,
                                          check_and_accept_tls_request,
                                          certificate_file_location,
                                          private_key_file_location,
                                          &bAccepted);
  }
  /////////////////////////////////////////////////////////////////////////
  // TML_CORE_HANDLE to send commands / messages 
  if (TML_SUCCESS == iErr)
  {
    iErr = tml_Core_Open(&coreSenderHandle, 0);
  }

  TML_CONNECTION_HANDLE connectionHandle = TML_HANDLE_TYPE_NULL;
  iErr = tml_Core_Connect(coreSenderHandle, DESTINATION_NETWORK_BINDING, &connectionHandle);
  /////////////////////////////////////////////////////////////////////////
  // Start tls negotiation for the requested connection
  if (TML_SUCCESS == iErr)
  {
    iErr = tml_Tls_Connection_StartNegotiation(connectionHandle, TML_FALSE, &bEncrypted);
  }

  if (!bEncrypted)
  {
#ifdef TML_UNICODE
      fwprintf (stderr, L"Cannot negotiate TLS-connection on listener side. Please insert valid \"%ls\" and certificate \"%ls\" file into executable working directory\n", TLS_KEY_FILE, TLS_CRT_FILE);
#else// TML_UNICODE
      printf ("Cannot negotiate TLS-connection on listener side. Please insert valid \"%s\" and certificate \"%s\" file into executable working directory\n", TLS_KEY_FILE, TLS_CRT_FILE);
#endif// TML_UNICODE
  }
  else
  {  
    /////////////////////////////////////////////////////////////////////////
    // Command / message creation:
    if (TML_SUCCESS == iErr)
    {
      iErr = createCmd4711(&cmdMsg, false);
    }

    /////////////////////////////////////////////////////////////////////////
    // send a loop of command / messages
    for (int i = 0; i < 10 && TML_SUCCESS == iErr; ++i)
    {
#ifdef TML_UNICODE
      fwprintf (stderr, L"Sending sync command 4711 to %ls -->\n", DESTINATION_HOST_IP);
#else// TML_UNICODE
      printf ("Sending sync command 4711 to %s -->\n", DESTINATION_HOST_IP);
#endif// TML_UNICODE
      iErr = tml_Connection_SendSync(connectionHandle, IO_PROFILE, cmdMsg, 10000);
      if (TML_SUCCESS == iErr)
      {
#ifdef TML_UNICODE
        fwprintf (stderr, L"Sending sync command 4711 (PROFILE2) to %ls -->\n", DESTINATION_HOST_IP);
#else // TML_UNICODE
        printf ("Sending sync command 4711 to %s -->\n", DESTINATION_HOST_IP);
#endif// TML_UNICODE
        iErr = tml_Connection_SendSync(connectionHandle, IO_PROFILE2, cmdMsg, 10000);
      }
    }
    ///////////////////////////////////////////////////////////////////////
    // Free the instance of Command / message HANDLE:
    if (TML_HANDLE_TYPE_NULL != cmdMsg)
    {
      tml_Cmd_Free(&cmdMsg);
    }
  }

  if (TML_HANDLE_TYPE_NULL != connectionHandle)
  {
    tml_Connection_Close(&connectionHandle);
  }
  ///////////////////////////////////////////////////////////////////////
  // Free the instances of TMLCore:
  if (TML_HANDLE_TYPE_NULL != coreSenderHandle)
  {
    tml_Core_Close(&coreSenderHandle);
  }

  if (TML_HANDLE_TYPE_NULL != coreListenerHandle)
  {
    tml_Core_Close(&coreListenerHandle);
  }

  ///////////////////////////////////////////////////////////////////////
  // Errorhandling:
  if (TML_SUCCESS != iErr)
  {
    printf ("TLS-Test / error happened - Code = %d\n", iErr);
  }

  return false;
}
Пример #13
0
/**
 * A simple async send / listen example with connection manange object
 */
bool sendAndListenTest04()
{
  TML_INT32 iErr = TML_SUCCESS; // API return value
  /////////////////////////////////////////////////////////////////////////
  // TML_CORE_HANDLE to receive commands / messages 
  TML_CORE_HANDLE coreListenerHandle = TML_HANDLE_TYPE_NULL;
  /////////////////////////////////////////////////////////////////////////
  // TML_CORE_HANDLE to send commands / messages 
  TML_CORE_HANDLE coreSenderHandle = TML_HANDLE_TYPE_NULL;
  /////////////////////////////////////////////////////////////////////////
  // TML_COMMAND_HANDLE Command / message HANDLE (internal represented by SIDEX data)
  TML_COMMAND_HANDLE cmdMsg  = TML_HANDLE_TYPE_NULL;
  /////////////////////////////////////////////////////////////////////////
  // Listener initialisation:
  iErr = initListener(&coreListenerHandle);
  /////////////////////////////////////////////////////////////////////////
  // TML_CORE_HANDLE to send commands / messages 
  if (TML_SUCCESS == iErr)
    iErr = tml_Core_Open(&coreSenderHandle, 0);

  TML_CONNECTION_HANDLE connectionHandle = TML_HANDLE_TYPE_NULL;
  iErr = tml_Core_Connect(coreSenderHandle, DESTINATION_NETWORK_BINDING, &connectionHandle);

  /////////////////////////////////////////////////////////////////////////
  // send a loop of command / messages
  for (int i = 10; i > 0 && TML_SUCCESS == iErr; --i){
    /////////////////////////////////////////////////////////////////////////
    // Command / message creation:
    if (TML_SUCCESS == iErr)
      iErr = createCmd4711(&cmdMsg, true);
    if (TML_SUCCESS == iErr){
#ifdef TML_UNICODE
      fwprintf (stderr, L"Sending async command 4711 to %ls -->\n", DESTINATION_HOST_IP);
#else// TML_UNICODE
      printf ("Sending async command 4711 to %s -->\n", DESTINATION_HOST_IP);
#endif// TML_UNICODE
      iErr = tml_Connection_SendAsync(connectionHandle, IO_PROFILE, cmdMsg, 500);

      if (TML_SUCCESS == iErr)
        iErr = createCmd4711(&cmdMsg, true);
      if (TML_SUCCESS == iErr){
  #ifdef TML_UNICODE
        fwprintf (stderr, L"Sending async command 4711 (PROFILE2) to %ls -->\n", DESTINATION_HOST_IP);
  #else// TML_UNICODE
        printf ("Sending async command 4711 to %s -->\n", DESTINATION_HOST_IP);
  #endif// TML_UNICODE
        iErr = tml_Connection_SendAsync(connectionHandle, IO_PROFILE2, cmdMsg, 500);
      }
    }
  }
  ///////////////////////////////////////////////////////////////////////
  // Wait for a while to be shure to be synchron with the asynchron callback
  // FOR THIS TEST to avoid a broken communication by closing the core handles
  wait (10000);
  ///////////////////////////////////////////////////////////////////////
  // Free the instances of TMLCore:
  if (TML_HANDLE_TYPE_NULL != coreSenderHandle)
    tml_Core_Close(&coreSenderHandle);
  if (TML_HANDLE_TYPE_NULL != coreListenerHandle)
    tml_Core_Close(&coreListenerHandle);

  ///////////////////////////////////////////////////////////////////////
  // Errorhandling:
  if (TML_SUCCESS != iErr)
    printf ("sendAndListenTest04 / error happened - Code = %d\n", iErr);
  return true;
}