/**
 * Update devicename, ip, port, public folder, and private folder
 * @param currentDevicename
 * @param newDevicename
 * @param username
 * @param ip
 * @param port
 * @param pulicFolder
 * @param privateFolder
 * @return 0 on success, -1 when currentDevice does not exist, otherwise DB
 * error code
 */
int DeviceCassandraController::updateDevice(
    const string &currentDevicename, const string &newDevicename,
    const string &username, const string &ip, const string &port,
    const string &publicFolder, const string &privateFolder) {
  string errorCode = "";
  int result;
  // Get the current device.
  boost::shared_ptr<Device> device =
      getDevice(currentDevicename, username, errorCode);
  if (!errorCode.empty()) {
    return boost::lexical_cast<int>(errorCode);
  }

  // Delete the current device from db.
  result = deleteDevice(currentDevicename, username);
  if (result != 0) {
    return result;
  }

  // Update data in the current device.
  device->setDevicename(newDevicename);
  device->setIp(ip);
  unsigned short portValue = -1;
  if (!ControllerHelper::isNullOREmptyString(port))
    portValue = boost::lexical_cast<unsigned short>(port);
  device->setPort(portValue);
  device->setPublicFolder(publicFolder);
  device->setPrivateFolder(privateFolder);

  // Add the new device.
  result = addDevice(device);
  return result;
}
Example #2
0
/* delete the property in the given device, including widgets and data structs.
 * when last property is deleted, delete the device too.
 * if no property name attribute at all, delete the whole device regardless.
 * return 0 if ok, else -1 with reason in errmsg[].
 */
int INDI::BaseClientQt::delPropertyCmd (XMLEle * root, char * errmsg)
{
    XMLAtt * ap;
    INDI::BaseDevice * dp;

    /* dig out device and optional property name */
    dp = findDev (root, 0, errmsg);
    if (!dp)
        return INDI_DEVICE_NOT_FOUND;

    dp->checkMessage(root);

    ap = findXMLAtt (root, "name");

    /* Delete property if it exists, otherwise, delete the whole device */
    if (ap)
    {
        INDI::Property * rProp = dp->getProperty(valuXMLAtt(ap));
        removeProperty(rProp);
        int errCode = dp->removeProperty(valuXMLAtt(ap), errmsg);

        return errCode;
    }
    // delete the whole device
    else
        return deleteDevice(dp->getDeviceName(), errmsg);
}
Example #3
0
void DeviceProvider::deleteDevices()
{	
	Devices	devices = mDevices;		// The copy is on purpose here
	for ( Devices::iterator itr=devices.begin(); itr!=devices.end(); itr++ )
	{
		Device* device = *itr;
		deleteDevice( device );
	}
	assert( mDevices.empty() );
}
 void deviceClose(oni::driver::DeviceBase* pDevice)
 {
   for (std::map<OniDeviceInfo, oni::driver::DeviceBase*>::iterator iter = devices.begin(); iter != devices.end();)
   {
     if (iter->second == pDevice)
     {
       WriteMessage("Closing device " + std::string(iter->first.uri));
       
       unsigned int id;
       std::istringstream is(std::string(iter->first.uri));
       is.seekg(strlen("freenect://"));
       is >> id;
       devices.erase(iter++);
       deleteDevice(id);
       return;
     }
     else
     {
int DeviceCassandraController::updateDevice(
    const string &devicename, const string &username,
    boost::unordered_map<string, string> &params) {
  if (params.size() <= 0)
    return 0;

  string errorCode = "";
  int result;

  // Get the current device.
  boost::shared_ptr<Device> device = getDevice(devicename, username, errorCode);
  if (!errorCode.empty()) {
    return boost::lexical_cast<int>(errorCode);
  }

  // Check if devicename needs to be changed.
  if (params.count("new_devicename")) {
    // Delete the current device from db.
    result = deleteDevice(devicename, username);
    if (result != 0) {
      return result;
    }
  }

  // Update data in the current device.
  if (params.count("new_devicename")) {
    device->setDevicename(params["new_devicename"]);
  }
  if (params.count("type")) {
    device->setType(params["type"]);
  }
  if (params.count("metadata")) {
    device->setContentMeta(params["metadata"]);
    device->setContentTimestamp(time(NULL));
  }
  if (params.count("dir_ip")) {
    device->setDirIp(params["dir_ip"]);
  }
  if (params.count("dir_port")) {
    unsigned short portValue = -1;
    if (!ControllerHelper::isNullOREmptyString(params["dir_port"]))
      portValue = boost::lexical_cast<unsigned short>(params["dir_port"]);
    device->setDirPort(portValue);
  }
  if (params.count("ip")) {
    device->setIp(params["ip"]);
  }
  if (params.count("port")) {
    unsigned short portValue = -1;
    if (!ControllerHelper::isNullOREmptyString(params["port"]))
      portValue = boost::lexical_cast<unsigned short>(params["port"]);
    device->setPort(portValue);
  }
  if (params.count("os")) {
    device->setOs(params["os"]);
  }
  if (params.count("description")) {
    device->setDescription(params["description"]);
  }
  if (params.count("public_folder")) {
    device->setPublicFolder(params["public_folder"]);
  }
  if (params.count("private_folder")) {
    device->setPrivateFolder(params["private_folder"]);
  }
  if (params.count("is_indexed")) {
    bool is_indexed = false;
    if (boost::iequals(params["is_indexed"], "true"))
      is_indexed = true;
    device->setSearchable(is_indexed);
  }

  // Update lastseen.
  device->setLastSeen(time(NULL));

  // Add the new device.
  result = addDevice(device);
  return result;
}
Example #6
0
 XorgFunction::~XorgFunction(void) {
   deleteDevice(dev) ;
 }
Example #7
0
  void
  XorgFunction::clearState(void) {
    deleteDevice(dev) ;
    dev = createDevice(ctrl_num, ctrl_den, ctrl_threshold, scheme, 
		       predictableProfile, corr_mul, const_acceleration, min_acceleration) ;
  }