コード例 #1
0
//added by Cristian.Guef
int NodesRepository::Add(const DevicePtr& node)
{
	if (!nodesByMAC.insert(NodesByMACT::value_type(node->Mac(), node)).second)
	{
		LOG_WARN("Same MAC:" << node->Mac().ToString() << "was detected (will be ignored)!");
		return 0;
	}
	return 1;
}
コード例 #2
0
AbstractAppCommandPtr AppCommandsFactory::Create(DBCommand& command, DevicesManager& devices)
{
	LOG_DEBUG_APP("[AppCommand]: create for db command:" << command);

	switch ( command.commandCode )
	{
	case DBCommand::ccGetTopology:
		CheckUsrCmdInputVal(devices).TestUsrParams_ccGetTopology(command);
		return AbstractAppCommandPtr(new AppTopologyCommand());

	case DBCommand::ccNotifSubscribe:
	{
		DevicePtr dev;
		CheckUsrCmdInputVal(devices).TestUsrParams_ccNotifSubscribe(command, dev);
		return AbstractAppCommandPtr(new AppSetBurstNotificationCmd(dev->GetPublisherInfo().channelList, 
			dev->GetPublisherInfo().burstMessageList, dev->GetPublisherInfo().triggersList));
	}
	case DBCommand::ccNotifUnSubscribe:
		CheckUsrCmdInputVal(devices).TestUsrParams_ccNotifUnSubscribe(command);
		return AbstractAppCommandPtr(new AppUnsetBurstNotificationCmd());
	
	case DBCommand::ccTopologyNotify:
		CheckUsrCmdInputVal(devices).TestUsrParams_ccTopologyNotify(command);
		return AbstractAppCommandPtr(new AppSetTopoNotificationCmd());

	case DBCommand::ccGeneralCmd:
	{
		int retValueCmdNo;  /* cmdNo */
		std::string retValueDataBytes; /* dataBytes */ 
		bool bypassIOCache;
		CheckUsrCmdInputVal(devices).TestUsrParams_ccGeneralCmd(command, retValueCmdNo, retValueDataBytes, bypassIOCache);
		return AbstractAppCommandPtr(new AppGeneralCommand(retValueCmdNo, retValueDataBytes, command.commandID, command.deviceID, bypassIOCache));	
	}
	case DBCommand::ccReadValue:
		{
		/*compute the channel list for the req cmd*/
		PublishChannel channel;
		bool bypassIOCache;
		CheckUsrCmdInputVal(devices).TestUsrParams_ccReadValue(command, channel, bypassIOCache);
		PublishChannelSetT channelsSet;
		channelsSet.insert(channel);
		return AbstractAppCommandPtr(new AppReadValueCmd( channel.cmdNo, command.deviceID, DeviceReading::ReadValue, channelsSet, bypassIOCache));
		}
	case DBCommand::ccRoutesReport:
		return AbstractAppCommandPtr(new AppRoutesReportCmd(devices.RegisteredDevicesNo()));
	case DBCommand::ccServicesReport:
		return AbstractAppCommandPtr(new AppServicesReportCmd(devices.RegisteredDevicesNo()));
	case DBCommand::ccDeviceHealthReport:
	{
		std::list<std::pair<int, MAC> > devicesList;
		CheckUsrCmdInputVal(devices).TestUsrParams_ccDevHealthReport(command, devicesList);
		return AbstractAppCommandPtr(new AppDeviceHealthReportCmd(devicesList));
	}
	case DBCommand::ccSuperframesReport:
		return AbstractAppCommandPtr(new AppSuperframesReportCmd(devices.RegisteredDevicesNo()));
	case DBCommand::ccDeviceScheduleLinkReport:
	{
		std::list<std::pair<int,MAC> > devicesList;
		CheckUsrCmdInputVal(devices).TestUsrParams_ccDeviceScheduleLinkReport(command, devicesList);
		return AbstractAppCommandPtr(new AppDeviceScheduleLinksReportCmd(devicesList));
	}		
	case DBCommand::ccNeighborHealthReport:
	{
		std::list<std::pair<int, MAC> > devicesList;
		CheckUsrCmdInputVal(devices).TestUsrParams_ccNeighborHealthReport(command, devicesList);
		return AbstractAppCommandPtr(new AppNeighborHealthReportCmd(devicesList));
	}
	case DBCommand::ccAutodetectBurstsConfig:
	{
		DevicePtr dev;
		std::string pubConfFileName;
		CheckUsrCmdInputVal(devices).TestUsrParams_ccBurstConfiguration(command, dev, pubConfFileName);
		//for cancelling command
		dev->configBurstDBCmdID = command.commandID;
		return AbstractAppCommandPtr(new AppSetBurstConfigurationCmd(pubConfFileName, dev));
	}
    case DBCommand::ccReadBurstConfig:
    {
        DevicePtr dev;
        CheckUsrCmdInputVal(devices).TestUsrParams_ccReadBurstConfig(command, dev);
        MAC mac = dev->Mac();
        return AbstractAppCommandPtr(new AppDiscoveryBurstConfigCmd(mac));
    }
	default:
		break;
	}

	LOG_ERROR_APP("[AppCommand]: create with Unknown CommandCode=" << command.commandCode);
	THROW_EXCEPTION1(InvalidCommandException, "unknown command");
}