Esempio n. 1
0
vector<StatisticsProviderDatatypes> IOstats::availableMetrics() throw() {
	vector<StatisticsProviderDatatypes> r;
	// walk through all known devices:

	// TODO: determine available DEVICES using /sys/block/
	// Could be combined using the library for detecting hardware in the KB?
	// Right now we consider DEVICES to be NODE metrics, although this is wrong.
	// It is NODE level for virtual devices and real DEVICES for existing hardware

	for( auto iterator = knownDevices.begin(); iterator != knownDevices.end(); iterator++ ) {
		string name = iterator->first;
		enum DeviceType type;
		string topologyPath = deviceName2topologyPath( name, type );

		knownDevices[name].type = type;

		//cout << name << endl;
		registerDevice(topologyPath, r,  knownDevices[name] );
	}

	registerDevice("@localhost", r, aggregated[DEVICE_TYPE_PHYSICAL]);
	registerDevice("@localhost/device:virtual:device", r, aggregated[DEVICE_TYPE_VIRTUAL]);
	registerDevice("@localhost/device:memory:device", r, aggregated[DEVICE_TYPE_MEMORY]);

	return r;
}
Esempio n. 2
0
bool NeuronPlugin::activate() {
    InputPlugin::activate();

    // register with userInputMapper
    auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
    userInputMapper->registerDevice(_inputDevice);

    // register c-style callbacks
    BRRegisterFrameDataCallback((void*)this, FrameDataReceivedCallback);
    BRRegisterCommandDataCallback((void*)this, CommandDataReceivedCallback);
    BRRegisterSocketStatusCallback((void*)this, SocketStatusChangedCallback);

    // TODO: Pull these from prefs dialog?
    // localhost is fine for now.
    _serverAddress = "localhost";
    _serverPort = 7001;  // default port for TCP Axis Neuron server.

    _socketRef = BRConnectTo((char*)_serverAddress.c_str(), _serverPort);
    if (!_socketRef) {
        // error
        qCCritical(inputplugins) << "NeuronPlugin: error connecting to " << _serverAddress.c_str() << ":" << _serverPort << ", error = " << BRGetLastErrorMessage();
        return false;
    } else {
        qCDebug(inputplugins) << "NeuronPlugin: success connecting to " << _serverAddress.c_str() << ":" << _serverPort;

        BRRegisterAutoSyncParmeter(_socketRef, Cmd_CombinationMode);
        return true;
    }
}
int main(int argc, char *argv[])
{
	if(argc < 3)
	{
		printf("Please provide exact number of arguments\n");
		return 0;
	}

	InitConfiguration(argv[1]);
	
	clnt = TryConnection();
	
	registerDevice(clnt);

	if(pthread_create(&tid,NULL,InitParams,(void*)argv[2]) != 0)
	{
		perror("Thread creation failed");
	}
	if(pthread_create(&tid,NULL,setTimeInterval,(void*)argv[2])!=0)
	{
		perror("Thread creation failed");
	}

	pthread_join(tid, NULL);	

	return 0;
}
Esempio n. 4
0
GamepadController::GamepadController()
    : m_gamepadDevices(Nix::Gamepads::itemsLengthCap)
{
    m_udev = udev_new();
    m_gamepadsMonitor = udev_monitor_new_from_netlink(m_udev, "udev");

    udev_monitor_enable_receiving(m_gamepadsMonitor);
    udev_monitor_filter_add_match_subsystem_devtype(m_gamepadsMonitor, "input", 0);

    GIOChannel *channel = g_io_channel_unix_new(udev_monitor_get_fd(m_gamepadsMonitor));
    g_io_add_watch(channel, GIOCondition(G_IO_IN), static_cast<GIOFunc>(&GamepadController::onGamepadChange), this);
    g_io_channel_unref(channel);

    struct udev_enumerate* enumerate = udev_enumerate_new(m_udev);
    udev_enumerate_add_match_subsystem(enumerate, "input");
    udev_enumerate_add_match_property(enumerate, "ID_INPUT_JOYSTICK", "1");
    udev_enumerate_scan_devices(enumerate);
    struct udev_list_entry* cur;
    struct udev_list_entry* devs = udev_enumerate_get_list_entry(enumerate);
    udev_list_entry_foreach(cur, devs)
    {
        const char* devname = udev_list_entry_get_name(cur);
        struct udev_device* device = udev_device_new_from_syspath(m_udev, devname);
        if (isGamepadDevice(device))
            registerDevice(udev_device_get_devnode(device));
        udev_device_unref(device);
    }
    udev_enumerate_unref(enumerate);
}
Esempio n. 5
0
bool LeapMotionPlugin::activate() {
    InputPlugin::activate();

    // Nothing required to be done to start up Leap Motion library.

    _joints.resize(LeapMotionJointIndex::Size, { glm::vec3(), glm::quat() });

    auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
    userInputMapper->registerDevice(_inputDevice);

    return true;
}
Esempio n. 6
0
bool TrackIRDevice::initialize()
{
	SURGSIM_ASSERT(!isInitialized()) << "TrackIR device already initialized.";
	auto scaffold = TrackIRScaffold::getOrCreateSharedInstance();
	SURGSIM_ASSERT(scaffold != nullptr) << "TrackIRDevice::initialize(): Failed to obtain a TrackIR scaffold.";

	bool initialize = false;
	if (scaffold->registerDevice(this))
	{
		m_scaffold = std::move(scaffold);
		initialize = true;
	}
	return initialize;
}
Esempio n. 7
0
void registerDevice(){
   REGISTER_DEVICE_PARAMS_t params;
   params.brand = "brand";
   params.device = "TI-J6";
   params.manufacturer = "manuf";
   params.model = "EVK";
   params.ibkey = MANUFACTURER_KEY;
   params.serial = "abcde12345";
   params.version = HRAD_API_VERSION;
   params.track = "true";
   params.cbFn = deviceRegisteredCB;

   hbr->registerDevice(&params);
}
bool antEnvironmentProcessing::appendEnvironmentSensor
(
    const amString &sensorID
)
{
    bool result = isEnvironmentSensor( sensorID );
    if ( result )
    {
        if ( !isRegisteredDevice( sensorID ) )
        {
            registerDevice( sensorID );
        }
    }
    return result;
}
Esempio n. 9
0
void registerDevice(){
   RegisterDeviceParams params;
   params.brand = "brand";
   params.device = "TI-J6";
   params.manufacturer = "manuf";
   params.model = "EVK";
   params.ibkey = MANUFACTURER_KEY;
   params.serial = "abcde12345";
   params.version = HRAD_API_VERSION;
   params.track = "true";

   hbr->registerDevice(params, [](const QString & ibd){
      qDebug() << TAG << "Device Registered: ibd = " << ibd;
      getStationModel(hbr->currentPublicStationID);
   });
}
Esempio n. 10
0
bool KinectPlugin::activate() {
    InputPlugin::activate();

    loadSettings();

    if (_enabled) {

        // register with userInputMapper
        auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
        userInputMapper->registerDevice(_inputDevice);

        return initializeDefaultSensor();
    } else {
        return false;
    }
}
Esempio n. 11
0
GamepadsEfl::GamepadsEfl(size_t length)
    : m_slots(length)
    , m_gamepadsWatcher(0)
{
    if (eeze_init() < 0) {
        LOG_ERROR("Failed to initialize eeze library.");
        return;
    }

    // Watch for gamepads additions / removals.
    m_gamepadsWatcher = eeze_udev_watch_add(EEZE_UDEV_TYPE_JOYSTICK, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), onGamePadChange, this);

    // List available gamepads.
    Eina_List* gamepads = eeze_udev_find_by_type(EEZE_UDEV_TYPE_JOYSTICK, 0);
    void* data;
    EINA_LIST_FREE(gamepads, data) {
        char* syspath = static_cast<char*>(data);
        registerDevice(String::fromUTF8(syspath));
        eina_stringshare_del(syspath);
    }
Esempio n. 12
0
bool antSpeedOnlyProcessing::appendSpeedSensor
(
    const amString &sensorID,
    double          wheelCircumference,
    double          nbMagnets
)
{
    bool result = isSpeedOnlySensor( sensorID );
    if ( result )
    {
        result = antSpeedProcessing::appendSpeedSensor( sensorID, wheelCircumference, nbMagnets );
        if ( result )
        {
            if ( !isRegisteredDevice( sensorID ) )
            {
                registerDevice( sensorID );
            }
        }
    }
    return result;
}
Esempio n. 13
0
File: ssu.cpp Progetto: jvihrial/ssu
void Ssu::requestFinished(QNetworkReply *reply){
  QSslConfiguration sslConfiguration = reply->sslConfiguration();
  SsuLog *ssuLog = SsuLog::instance();
  SsuCoreConfig *settings = SsuCoreConfig::instance();
  QNetworkRequest request = reply->request();
  QVariant originalDomainVariant = request.attribute(SSU_NETWORK_REQUEST_DOMAIN_DATA);

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
  ssuLog->print(LOG_DEBUG, QString("Certificate used was issued for '%1' by '%2'. Complete chain:")
                .arg(sslConfiguration.peerCertificate().subjectInfo(QSslCertificate::CommonName).join(""))
                .arg(sslConfiguration.peerCertificate().issuerInfo(QSslCertificate::CommonName).join("")));

  foreach (const QSslCertificate cert, sslConfiguration.peerCertificateChain()){
    ssuLog->print(LOG_DEBUG, QString("-> %1").arg(cert.subjectInfo(QSslCertificate::CommonName).join("")));
  }
#else
  ssuLog->print(LOG_DEBUG, QString("Certificate used was issued for '%1' by '%2'. Complete chain:")
               .arg(sslConfiguration.peerCertificate().subjectInfo(QSslCertificate::CommonName))
               .arg(sslConfiguration.peerCertificate().issuerInfo(QSslCertificate::CommonName)));

  foreach (const QSslCertificate cert, sslConfiguration.peerCertificateChain()){
    ssuLog->print(LOG_DEBUG, QString("-> %1").arg(cert.subjectInfo(QSslCertificate::CommonName)));
  }
#endif

  pendingRequests--;

  QString action;
  QByteArray data;
  QDomDocument doc;
  QString xmlError;

  /// @TODO: indicate that the device is not registered if there's a 404 on credentials update url
  if (settings->contains("home-url")){
    QString homeUrl = settings->value("home-url").toString().arg("");
    homeUrl.remove(QRegExp("//+$"));

    if (request.url().toString().startsWith(homeUrl, Qt::CaseInsensitive)){
      // we don't care about errors on download request
      if (reply->error() == 0) {
          QByteArray data = reply->readAll();
          storeAuthorizedKeys(data);
      }

      goto success;
    }
  }

  if (reply->error() > 0){
    setError(reply->errorString());
    goto failure;
  }

  data = reply->readAll();
  ssuLog->print(LOG_DEBUG, QString("RequestOutput %1")
                .arg(data.data()));

  if (!doc.setContent(data, &xmlError)){
    setError(tr("Unable to parse server response (%1)").arg(xmlError));
    goto failure;
  }

  action = doc.elementsByTagName("action").at(0).toElement().text();

  if (!verifyResponse(&doc)) {
    goto failure;
  }

  ssuLog->print(LOG_DEBUG, QString("Handling request of type %1")
                .arg(action));
  if (action == "register") {
    if (registerDevice(&doc)) {
      goto success;
    }
  } else if (action == "credentials") {
    if (setCredentials(&doc)) {
      goto success;
    }
  } else {
    setError(tr("Response to unknown action encountered: %1").arg(action));
  }

failure:
  // Restore the original domain in case of failures with the registration
  if (!originalDomainVariant.isNull()) {
    QString originalDomain = originalDomainVariant.toString();
    ssuLog->print(LOG_DEBUG, QString("Restoring domain on error: '%1'").arg(originalDomain));
    setDomain(originalDomain);
  }

  // Fall through to cleanup handling in success from failure label
success:
  ssuLog->print(LOG_DEBUG, QString("Request finished, pending requests: %1").arg(pendingRequests));
  if (pendingRequests == 0) {
    emit done();
  }
}
Esempio n. 14
0
File: ssu.cpp Progetto: lbt/ssu
void Ssu::requestFinished(QNetworkReply *reply){
  QSslConfiguration sslConfiguration = reply->sslConfiguration();
  SsuLog *ssuLog = SsuLog::instance();
  SsuCoreConfig *settings = SsuCoreConfig::instance();

  ssuLog->print(LOG_DEBUG, QString("Certificate used was issued for '%1' by '%2'. Complete chain:")
               .arg(sslConfiguration.peerCertificate().subjectInfo(QSslCertificate::CommonName))
               .arg(sslConfiguration.peerCertificate().issuerInfo(QSslCertificate::CommonName)));

  foreach (const QSslCertificate cert, sslConfiguration.peerCertificateChain()){
    ssuLog->print(LOG_DEBUG, QString("-> %1").arg(cert.subjectInfo(QSslCertificate::CommonName)));
  }

  // what sucks more, this or goto?
  do {
    if (settings->contains("home-url")){
      QString homeUrl = settings->value("home-url").toString().arg("");
      homeUrl.remove(QRegExp("//+$"));
      QNetworkRequest request = reply->request();

      if (request.url().toString().startsWith(homeUrl, Qt::CaseInsensitive)){
        // we don't care about errors on download request
        if (reply->error() > 0) break;
        QByteArray data = reply->readAll();
        storeAuthorizedKeys(data);
        break;
      }
    }

    if (reply->error() > 0){
      pendingRequests--;
      setError(reply->errorString());
      return;
    } else {
      QByteArray data = reply->readAll();
      qDebug() << "RequestOutput" << data;

      QDomDocument doc;
      QString xmlError;
      if (!doc.setContent(data, &xmlError)){
        pendingRequests--;
        setError(tr("Unable to parse server response (%1)").arg(xmlError));
        return;
      }

      QString action = doc.elementsByTagName("action").at(0).toElement().text();

      if (!verifyResponse(&doc)) break;

      if (action == "register"){
        if (!registerDevice(&doc)) break;
      } else if (action == "credentials"){
        if (!setCredentials(&doc)) break;
      } else {
        pendingRequests--;
        setError(tr("Response to unknown action encountered: %1").arg(action));
        return;
      }
    }
  } while (false);

  pendingRequests--;

  ssuLog->print(LOG_DEBUG, QString("Request finished, pending requests: %1").arg(pendingRequests));
  if (pendingRequests == 0)
    emit done();
}
// Tokenize incoming message
void handleMessage(char *message, int sockfd) {
int dsock,n;
if (strstr(message, "register") != NULL) {
	char *str = strtok(message, ";");
	str = strtok(NULL, ";");
	str = strtok(str,":");
	str = strtok(NULL,":");
	stype = strtok(str, "-");//sensor
	//printf("Type : %s\n",stype);
	sipaddress = strtok(NULL, "-");//ipaddress
	//printf("Sipaddress : %s\n",sipaddress);
	sport = strtok(NULL, "-");//port
	//printf("Sport : %s\n",sport);
	sarea = strtok(NULL, "-");//area
	//printf("Area : %s\n",sarea);
	// Registering device
	registerDevice(sockfd);
	//printStatus();
    } 
else if (strstr(message, "currValue") != NULL) {
	//printf("Inside currValue.\n");
	
	char *str = strtok(message, ";");
	str = strtok(NULL, ";");
	str = strtok(str,":");
	str = strtok(NULL, ":");
	//printf("currValue : %s\n",str);
	// Flushing the number
        numberofsensor = 0;
		int areacode;
		int currValue;
	struct device *ptr = start;
	while(ptr != NULL)
	{
		if(ptr->sockFD == sockfd){
			if(ptr->currValue == atoi(str)){
			//printf("Inside Equal\n");
			return;
			//printf("After return\n");
			}
			ptr->currValue = atoi(str);
			areacode = ptr->areaCode;
			currValue = ptr->currValue;
			break;
		}
		ptr = ptr->next;
	}
	struct device *pointer = start;
	if (currValue < 32) {
		switchSmartDevice(areacode, 1);
	} else if (currValue > 34) {
		int flag = 1;
		while(pointer != NULL)
		{
			if(pointer->areaCode == areacode && strcmp(pointer->type, "sensor") == 0 && pointer->status == 1) {
				if (pointer->currValue <=34 ) {
					flag = 0;
					break;
				} 
			}
			pointer = pointer->next;
		}
		if (flag == 1) {
			switchSmartDevice(areacode, 0);
		}
		
	}
	
    }

else if(strstr(message, "currState") != NULL) {
	char *str = strtok(message, ";");
	str = strtok(NULL, ";");
	str = strtok(str,":");
	str = strtok(NULL,":");
	printf("Value : %s\n",str);
    }

   printf("--------------------------------------------------------\n");
   printStatus();
   printf("--------------------------------------------------------\n");

}
Esempio n. 16
0
int main()
{
   registerDevice();
   getStationModel(0);
   return 0;
}
Esempio n. 17
0
int main()
{
   registerDevice();
   return 0;
}