Пример #1
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
    Gateway gateway;

    return gateway.run (argc, argv);
}
Пример #2
0
static void* serve(void* arg)
{
	Gateway* gateway = (Gateway*)arg;

	gateway->serve();

	return 0;
}
Пример #3
0
int main(int argc, const char * argv[]) {
    Gateway gateway = Gateway();
    GatewayFilter filter = GatewayFilter();
    struct gwFilterData gwFD;
    gwFD.st = &gateway.st;
    gwFD.gw = &gateway;
    Logger::initLog("gout.txt");

    filter.startFilterThread(&gwFD);

    gateway.initBlacklist();

    pthread_t taskThread;
    pthread_t blockThread;

    sem_init(&Gateway::sem, 0 , 0);
    sem_init(&Gateway::qsem, 0 , 1);
    sem_init(&Gateway::lsem, 0, 1);

    pthread_create(&taskThread, NULL, &gatewayTaskThread, (void *) &gateway);
    pthread_create(&blockThread, NULL, &gatewayBlockCleanupThread, (void *) &gateway);

    int s = -1;
    while(s < 0){
        s = socket(AF_INET, SOCK_STREAM, 0);
    }

    addrinfo hints, *res;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = AI_PASSIVE;

    getaddrinfo(NULL, "41025", &hints, &res);

    bind(Gateway::s, res->ai_addr, res->ai_addrlen);

    listen(Gateway::s,10);

    int len;
    char buf[1024];
    sockaddr_storage their_addr;
    for(;;){
        unsigned int addr_size = sizeof(their_addr);
        int sock = accept(Gateway::s, (sockaddr *) &their_addr, &addr_size);
        addr_size = sizeof(their_addr);
        getpeername(sock, (sockaddr *) &their_addr, &addr_size);
        struct sockaddr_in *saddr = (struct sockaddr_in *)&their_addr;
        char addr[1000];
        inet_ntop(AF_INET, &saddr->sin_addr, addr, 1000);
        Logger::writeToLog("accept()ed a connection from " + std::string(addr));
        pthread_t t;
        pthread_create(&t, NULL, &recvBlockReq, (void *)sock);
    }
}
Пример #4
0
    void init() {
        //router.addGateway(&gateway1);
        //router.addGateway(&gateway2);

#ifdef USE_UART_CONN
        gatewayUart.resetTopicsToForward();
        gatewayUart.addTopicsToForward(&counter1,&counter2);

        router.addGateway(&gatewayUart);
#endif

    }
Пример #5
0
int main()
{
    Gateway gate;

    auto cfg = GetConfig();
    if (cfg.empty()) {
        return 0;
    }

    try {
        gate.Run(cfg[0], cfg[1], atoi(cfg[2].c_str()));
    } catch (std::exception& e) {
        LOG("exception: %s", e.what());
    }
}
Пример #6
0
int main(int argc, char* argv[]) {
    std::string workingDir = getexepath() + "/../DB";
    workingDir = "/home/bele/git/arduino-mqtt-sn-gateway/cmake-build-debug/DB";
    persistent.setRootPath((char *) workingDir.c_str());
    setup();
    while(true){
        gateway.loop();
    }
}
Пример #7
0
Gateway*
NetworkManager::GetGatewayByID (int idGW)
{
  std::vector<Gateway*>* gatewayContainer = GetGatewayContainer ();
  std::vector<Gateway*>::iterator iter;
  Gateway *gateway;

  for (iter = gatewayContainer->begin ();
      iter !=gatewayContainer->end (); iter++)
    {
    gateway = *iter;
    if (gateway->GetIDNetworkNode() == idGW)
      {
      return gateway;
      }
    }
  return false;
}
Пример #8
0
NetworkNode*
NetworkManager::GetNetworkNodeByID (int id)
{
  std::vector<ENodeB*>* eNodeBContainer = GetENodeBContainer ();
  std::vector<ENodeB*>::iterator iter2;
  ENodeB *eNodeB;
  for (iter2 = eNodeBContainer->begin ();
      iter2 !=eNodeBContainer->end (); iter2++)
    {
    eNodeB = *iter2;
    if (eNodeB->GetIDNetworkNode() == id)
      {
      return eNodeB;
      }
    }

  std::vector<UserEquipment*>* userEquipmentContainer = GetUserEquipmentContainer ();
  std::vector<UserEquipment*>::iterator iter3;
  UserEquipment *userEquipment;
  for (iter3 = userEquipmentContainer->begin ();
      iter3 !=userEquipmentContainer->end (); iter3++)
    {
    userEquipment = *iter3;
    if (userEquipment->GetIDNetworkNode() == id)
      {
      return userEquipment;
      }
    }

  std::vector<Gateway*>* gatewayContainer = GetGatewayContainer ();
  std::vector<Gateway*>::iterator iter;
  Gateway *gateway;

  for (iter = gatewayContainer->begin ();
      iter !=gatewayContainer->end (); iter++)
    {
    gateway = *iter;
    if (gateway->GetIDNetworkNode() == id)
      {
      return gateway;
      }
    }
  return false;
}
Пример #9
0
void GatewayPacketHandler::OnRecvExterPacket(int nSrcSessionID, Packet *poPacket, EXTER_HEADER& oHeader)
{
	Gateway* poGateway = (Gateway*)g_poContext->GetService();
	if (oHeader.nTarService == poGateway->GetServiceID() || oHeader.uCmd == NSCltSrvCmd::ppKeepAlive)
	{
		PacketProcIter iter = m_poExterPacketProcMap->find(oHeader.uCmd);
		if (iter != m_poExterPacketProcMap->end())
		{
			(*(ExterPacketProc)(iter->second->pProc))(nSrcSessionID, poPacket, oHeader);
		}
		else
		{
			XLog(LEVEL_ERROR, "CMD:%d proc not found\n", oHeader.uCmd);
		}
		poPacket->Release();
	} 
	else
	{
		//Send to logic server
		if (oHeader.nTarService == 0)
		{
			oHeader.nTarService = poGateway->GetClientMgr()->GetClientLogicService(nSrcSessionID);
			if (oHeader.nTarService <= 0)
			{
				oHeader.nTarService = g_poContext->GetRandomLogic();
			}
			if (oHeader.nTarService <= 0)
			{
				XLog(LEVEL_ERROR, "%s: Player logic server error\n", poGateway->GetServiceName());
				poPacket->Release();
				return;
			}
		}
		if (!NetAdapter::SendInner(oHeader.uCmd, poPacket, oHeader.nTarService, nSrcSessionID))
		{
			XLog(LEVEL_ERROR, "%s: Send packet to router fail\n", poGateway->GetServiceName());
		}
	}
}
Пример #10
0
void setup() {
    logger.start_log("Linux MQTT-SN Gateway version 0.0.1a starting", 1);
    logger.append_log("Ethernet connected!");

    gateway.setLoggerInterface(&logger);
    gateway.setSocketInterface(&udpSocket);
    gateway.setMqttInterface(&mqtt);
    gateway.setPersistentInterface(&persistent);
    gateway.setSystemInterface(&systemImpl);

    while (!gateway.begin()) {
        logger.log("Error starting gateway components", 0);
        systemImpl.sleep(5000);
        systemImpl.exit();
    }
    logger.log("Gateway ready", 1);
}
Пример #11
0
void WifiGateway::init() {
	gateway1.addTopicsToForward(&imu_data, &light_data, &PowerTopic);
	gateway1.addTopicsToForward(&gyr_data, &xm_data, &TelecommandTopic);
}
double GatewayPathfindingStateSpaceMP::shortestDistanceToGate(Tile tile, Gateway gateway)
{
	Tile gateStart = gateway.getStart();
	Tile gateEnd = gateway.getEnd();

	int deltaX = 0;
	int deltaY = 0;

	if(gateStart.x == gateEnd.x) {  //Vertical gate
		int higherY, lowerY;
		if(gateStart.y > gateEnd.y) {
			higherY = gateStart.y;
			lowerY = gateEnd.y;
		}
		else {
			higherY = gateEnd.y;
			lowerY = gateStart.y;
		}
		if(tile.y > higherY) {
			deltaY = tile.y - higherY;
		}
		else if(tile.y < lowerY) {
			deltaY = lowerY - tile.y;
		}
		deltaX = tile.x - gateStart.x;
	}
	else if(gateStart.y == gateEnd.y) {  //Horizontal gate
		int higherX, lowerX;
		if(gateStart.x > gateEnd.x) {
			higherX = gateStart.x;
			lowerX = gateEnd.x;
		}
		else {
			higherX = gateEnd.x;
			lowerX = gateStart.x;
		}
		if(tile.x > higherX) {
			deltaX = tile.x - higherX;
		}
		else if(tile.x < lowerX) {
			deltaX = lowerX - tile.x;
		}
		deltaY = tile.y - gateStart.y;
	}
	else {  //Diagonal gate (always 45 degrees)
		int higherX, lowerX;
		int higherY, lowerY;
		bool backslashGate = false;
		if(gateStart.y > gateEnd.y) {
			higherY = gateStart.y;
			lowerY = gateEnd.y;
			if(gateStart.x > gateEnd.x) {
				higherX = gateStart.x;
				lowerX = gateEnd.x;
				backslashGate = false;
			}
			else {
				higherX = gateEnd.x;
				lowerX = gateStart.x;
				backslashGate = true;
			}
		}
		else {
			higherY = gateEnd.y;
			lowerY = gateStart.y;
			if(gateStart.x > gateEnd.x) {
				higherX = gateStart.x;
				lowerX = gateEnd.x;
				backslashGate = true;
			}
			else {
				higherX = gateEnd.x;
				lowerX = gateStart.x;
				backslashGate = false;
			}
		}
		if(backslashGate) {
			if(tile.y > (higherY - (lowerX - tile.x))) {
				deltaX = tile.x - lowerX;
				deltaY = tile.y - higherY;
			}
			else if(tile.y < (lowerY - (higherX - tile.x))) {
				deltaX = higherX - tile.x;
				deltaY = lowerY - tile.y;
			}
			else {
				deltaX = deltaY =
					( (tile.x - lowerX)
					+ (tile.x - higherX)
					+ (tile.y - lowerY)
					+ (tile.y - higherY) )
					/ 4;
			}
		}
		else {
			if(tile.y > (higherY - (tile.x - higherX))) {
				deltaX = tile.x - higherX;
				deltaY = tile.y - higherY;
			}
			else if(tile.y < (lowerY - (tile.x - lowerX))) {
				deltaX = lowerX - tile.x;
				deltaY = lowerY - tile.y;
			}
			else {
				deltaX = deltaY =
					( (tile.x - lowerX)
					+ (tile.x - higherX)
					+ (lowerY - tile.y)
					+ (higherY - tile.y) )
					/ 4;
			}
		}
	}
	return octileDistance(deltaX, deltaY);
}