Пример #1
0
Mesh* createMeshFromResource(const std::string& resource, const Eigen::Vector3d &scale)
{
  resource_retriever::Retriever retriever;
  resource_retriever::MemoryResource res;
  try
  {
    res = retriever.get(resource);
  } 
  catch (resource_retriever::Exception& e)
  {
    logError("%s", e.what());
    return NULL;
  }

  if (res.size == 0)
  {
    logWarn("Retrieved empty mesh for resource '%s'", resource.c_str());
    return NULL;
  }
  
  Mesh *m = createMeshFromBinary(reinterpret_cast<const char*>(res.data.get()), res.size, scale, resource);
  if (!m)
    logWarn("Assimp reports no scene in %s", resource.c_str());
  return m;
}
Пример #2
0
void DisplayClient::appClientReceiveMulticast(int servicePort, SYNTRO_EHEAD *multiCast, int len)
{
	// make sure this is for us
	if (servicePort != m_receivePort) {
		logWarn(QString("Multicast received to invalid port %1").arg(servicePort));
		free(multiCast);
		return;
	}

	// and the size we expect
	if (len != (sizeof(SYNTRO_RECORD_HEADER) + sizeof(quint32))) {
		logWarn(QString("Multicast length is unexpected : %1").arg(len - sizeof(SYNTRO_RECORD_HEADER)));
		free(multiCast);
		return;
	}

	// unpack the record, first get a pointer to the SYNTRO_RECORD_HEADER
	SYNTRO_RECORD_HEADER *head = (SYNTRO_RECORD_HEADER *)(multiCast + 1);

	// the led data is immediately after the SYNTRO_RECORD_HEADER in a single quint32
	quint32 *values = (quint32 *)(head + 1);

	// the BoneLedDisplay class catches this signal
	emit newData(*values);

	// ack the data
	clientSendMulticastAck(servicePort);

	// always free the record you are given
	free(multiCast);
}
Пример #3
0
bool shares_reload() {
	pthread_mutex_lock(&shareMutex);
	int fd;
	char* shareFilename = shareList->shareFile;
	char line[PATH_MAX];

	logDebug("share reload");

	if (shareFilename == NULL) {
		logWarn("There is no share list to reload");
		pthread_mutex_unlock(&shareMutex);
		return false;
	}

	if (!fs_exist(shareFilename)) {
		logWarn("The share list file '%s' do not exist", shareFilename);
		pthread_mutex_unlock(&shareMutex);
		return false;
	}

	shares_clearList();

	fd = file_open(shareFilename);

	while (file_readLine(fd, line)) {
		shares_parse(line);
	}

	pthread_mutex_unlock(&shareMutex);
	return true;
}
Пример #4
0
bool ini_addSection(Ini* ini, const char* sectionName) {
	if (ini == NULL) {
		logWarn("Invalid ini object");
		return false;
	}

	if (sectionName == NULL) {
		logWarn("Section name is NULL");
		return false;
	}

	if (ini_get(ini, sectionName) != NULL) {
		logWarn("Section '%s' already exist", sectionName);
		return false;
	}

	Section* section = memory_new(Section, true);
	str_ncpy(section->name, sectionName, sizeof(section->name));
	section->keys = list_new(true);
	section->values = list_new(true);

	list_add(ini->sections, (Any)section);

	return true;
}
Пример #5
0
void PeerAdmin::processServer(ServerSocketChannelPtr socket, SharedPtr< Peer::Factory > factory) {
	try {
		SocketChannelPtr clientSocket = socket->accept();
		clientSocket->registerTo(m_selector, SelectionKey::OP_READ, factory->build(clientSocket));
	} catch (Exception &e) {
		logWarn() << __demangle(typeid(*this).name()) << " Close peer connection after throwing an instance of '" << __demangle(typeid(e).name()) << "'";
		if (!e.message().isEmpty())
			logWarn() << "  what(): " << e.message();
	}
	socket->registerTo(m_selector, SelectionKey::OP_READ, factory);
}
kinematic_constraints::ConstraintEvaluationResult kinematic_constraints::JointConstraint::decide(const robot_state::RobotState &state, bool verbose) const
{
  if (!joint_model_)
    return ConstraintEvaluationResult(true, 0.0);

  const robot_state::JointState *joint = state.getJointState(joint_model_->getName());

  if (!joint)
  {
    logWarn("No joint in state with name '%s'", joint_model_->getName().c_str());
    return ConstraintEvaluationResult(true, 0.0);
  }

  double current_joint_position = joint->getVariableValues()[0];
  if (!local_variable_name_.empty())
  {
    const std::map<std::string, unsigned int> &index_map = joint->getVariableIndexMap();
    std::map<std::string, unsigned int>::const_iterator it = index_map.find(joint_variable_name_);
    if (it == index_map.end())
    {
      logWarn("Local name '%s' is not known to joint state with name '%s'", local_variable_name_.c_str(), joint_model_->getName().c_str());
      return ConstraintEvaluationResult(true, 0.0);
    }
    else
      current_joint_position = joint->getVariableValues()[it->second];
  }

  double dif = 0.0;

  // compute signed shortest distance for continuous joints
  if (joint_is_continuous_)
  {
    dif = normalizeAngle(current_joint_position) - joint_position_;

    if (dif > boost::math::constants::pi<double>())
      dif = 2.0*boost::math::constants::pi<double>() - dif;
    else
      if (dif < -boost::math::constants::pi<double>())
        dif += 2.0*boost::math::constants::pi<double>(); // we include a sign change to have dif > 0
  }
  else
    dif = current_joint_position - joint_position_;

  // check bounds
  bool result = dif <= (joint_tolerance_above_+2*std::numeric_limits<double>::epsilon()) && dif >= (-joint_tolerance_below_-2*std::numeric_limits<double>::epsilon());
  if (verbose)
    logInform("Constraint %s:: Joint name: '%s', actual value: %f, desired value: %f, tolerance_above: %f, tolerance_below: %f",
              result ? "satisfied" : "violated", joint_variable_name_.c_str(),
              current_joint_position, joint_position_, joint_tolerance_above_, joint_tolerance_below_);
  return ConstraintEvaluationResult(result, constraint_weight_ * fabs(dif));
}
Пример #7
0
static bool ini_parseKey(Ini* ini, char* line) {
	int i = 0;
	char key[256];
	char value[1024];
	int strLen = str_len(line);
	bool keyFound = false;
	Section* section;

	key[0] = '\0';
	value[0] = '\0';

	for (i = 0; i < strLen; i++) {
		if (keyFound) {
			str_ncpy(value, (line + i), strLen - i);
			value[strLen - i] = '\0';
			break;
		}

		if ((line[i] == '=') && keyFound == false) {
			keyFound = true;
			str_ncpy(key, line, i);
			key[i] = '\0';
			continue;
		}
	}

	str_trim(key);
	str_trim(value);

	if (str_len(key) == 0) {
		logWarn("No key in line '%s'", line);
		return false;
	}

	if (str_len(value) == 0) {
		logWarn("No value in line '%s'", line);
		return false;
	}

	if (ini->sections->size == 0) {
		logWarn("There is no section to add the key");
		return false;
	}

	// Get the last section added
	section = (Section*)list_get(ini->sections, (ini->sections->size - 1));
	return ini_addKey(ini, section, key, value);
}
Пример #8
0
/**
 * Read file, returning contents in buf
 *
 * @return file size on success, -1 on error
 */
static int readFile(const char *filename, char **buf)
{
    int fd, res;
    struct stat statBuf;

    logVerb("%s('%s')\n", __func__, filename);

    if ((fd = open(filename, O_RDONLY, S_IRUSR | S_IWUSR)) < 0) {
    	if (errno == ENOENT)
    		logWarn("File '%s' not found\n", filename);
        return fd;
    }

    if ((res = stat(filename, &statBuf)) < 0) {
        logSysError("%s.stat\n",  __func__);
        return res;
    }

    *buf = malloc(statBuf.st_size + 1);

    if (read(fd, *buf, statBuf.st_size) < 0)
        dieSysError("read()\n");

    close(fd);

    return statBuf.st_size;
}
Пример #9
0
void Master::onStart() {
	CliArguments &args = CliArguments::getInstance();
#ifdef WIN32
	m_settings = new Settings("mbedsys.org", "NodeBus", QSettings::NativeFormat);
#else
	m_settings = new Settings(args.getValue("config").toString(), QSettings::NativeFormat);
#endif
	m_settings->define("master/pidfile",	tr("Path of the file where the service PID will be written in"),
					NODEBUS_DEFAULT_PIDFILE);
	m_settings->define("master/bundle-rootpath",	tr("Bundle root directory path"), 
					NODEBUS_DEFAULT_PLUGIN_DIR_PATH);
	m_settings->define("master/registry-service-name",	tr("Registry service name"), 
					NODEBUS_DEFAULT_REGISTRY_SERVICE_NAME);
	if (args.isEnabled("edit-settings")) {
		m_settings->setup();
		throw ExitApplicationException();
	}
	QString path = m_settings->value("master/bundle-rootpath").toString();
	QDirIterator it(path, QStringList("*.so"), QDir::Files, QDirIterator::Subdirectories);
	logFiner() << "Search for bundles in the directory " << path;
	while (it.hasNext()) {
		QString file = it.next();
		logFinest() << "Found file " << file;
		try {
			BundlePtr bundle = new Bundle(file);
			m_bundles[bundle->property("Bundle-SymbolicName").toString()] = bundle;
			logFine() << "Found bundle " << bundle->property("Bundle-Name") << " (" << bundle->property("Bundle-SymbolicName") << ')';
		} catch (Exception &e) {
			logWarn() << "Invalid bundle file " << file << " (" << e.message() << ')';
		}
	}
	if (m_bundles.isEmpty()) {
		throw ApplicationException("No valid bundle found in the directory " + path);
	}
}
Пример #10
0
Matrix4f Node::getGlobalTransform(bool with_scale) const
{
    Matrix4f ret;

    Matrix4f self_mat;

    if(with_scale) {
        const Transformf* trans = static_cast<const Transformf*>(this);
        self_mat = Matrix4f(*trans);
    } else {
        self_mat = Matrix4f(rotation,position);
    }

    if(parent() != 0)
    {
        if(parent()->type() == ParentOfNode::NODE)
        {
            const Node* parentNode = static_cast<const Node*>(parent());
            ret = parentNode->getGlobalTransform(with_scale) * self_mat;
        }
        else
        {
            ret = self_mat;
        }
    }
    else
    {
        logWarn("trying to access globalTransform on unlinked node");
    }
    return ret;
}
Пример #11
0
int main(int argc, char *argv[])
{
  /* dbgmsg()
  ** You can use '|dbgmsg()| exactly as if it was '|printf()| the difference
  ** is that the output will go on the file defined with '|utlSetOuput()| 
  ** (or '|stderr| if no file has been specified)     
  */  
  
  dbgmsg("This message will go on stderr %d\n",1);
  utlSetOutput("utlh1.dbg");
  dbgmsg("This message is on utlh1.log");
  utlSetOutput("utlh2.dbg"); /* the previous file is closed and the new one is opened*/
  dbgmsg("This message is on utlh2.log");
  utlSetOutput(NULL); 
  dbgmsg("This message will go on stderr %d",2);

  
  /* Logging is different from debugging messages in that the logging will
  ** remain in your production code and you will be able to enable it to
  ** monitor the application behavior.  
  */
    
  logSetLevel(logALL);
  logDebug("This is a log debug message. (%d)",logLevel);
  logSetLevel(logINFO);
  logDebug("This will not appear");
  logMessage("\n%s...continuing",logIndent);
  logWarn("And now a warning (%d)",5);
  logSetFile("utlh1.log","w");
  logError("An error!");
  logFatal("An unrecoverable error");
   
  return (0);
}
Пример #12
0
void StbImageFactory::load(ResourceData *resource)
{
    StbImage* stbresource = static_cast<StbImage*>(resource);
    int x,y,comp;

    stbi_uc* data = stbi_load(stbresource->path().toLocal8Bit().data(), &x, &y, &comp, stbresource->m_comp);

    if(data != 0)
    {
        logInfo( "StbImage loaded " << resource->name() << " (" << x << "x" << y << ")");
        stbresource->m_data = data;
        stbresource->m_width = x;
        stbresource->m_height = y;

        // If we asked 0 components comp now contains the number of components
        if(stbresource->m_comp == 0)
            stbresource->m_comp = comp;

        stbresource->m_state = StbImage::STATE_LOADED;
        stbresource->buildTexture();
    }
    else
    {
        logWarn( "StbImage failed to load " << resource->name() << "\n" << stbi_failure_reason());
    }
}
Пример #13
0
  bool operator()(const ConstraintSamplerPtr &a, const ConstraintSamplerPtr &b) const
  {
    const std::vector<std::string> &alinks = a->getJointModelGroup()->getUpdatedLinkModelNames();
    const std::vector<std::string> &blinks = b->getJointModelGroup()->getUpdatedLinkModelNames();
    std::set<std::string> a_updates(alinks.begin(), alinks.end());
    std::set<std::string> b_updates(blinks.begin(), blinks.end());

    bool a_contains_b = std::includes(a_updates.begin(), a_updates.end(),
                                      b_updates.begin(), b_updates.end());

    bool b_contains_a = std::includes(b_updates.begin(), b_updates.end(),
                                      a_updates.begin(), a_updates.end());

    //a contains b and sets are not equal
    if (a_contains_b && !b_contains_a)
      return true;
    if (b_contains_a && !a_contains_b)
      return false;

    //sets are equal or disjoint
    bool a_depends_on_b = false;
    bool b_depends_on_a = false;
    const std::vector<std::string> &fda = a->getFrameDependency();
    const std::vector<std::string> &fdb = b->getFrameDependency();
    for (std::size_t i = 0 ; i < fda.size() && !a_depends_on_b ; ++i)
      for (std::size_t j = 0 ; j < blinks.size() ; ++j)
        if (blinks[j] == fda[i])
        {
          a_depends_on_b = true;
          break;
        }
    for (std::size_t i = 0 ; i < fdb.size() && !b_depends_on_a ; ++i)
      for (std::size_t j = 0 ; j < alinks.size() ; ++j)
        if (alinks[j] == fdb[i])
        {
          b_depends_on_a = true;
          break;
        }
    if (b_depends_on_a && a_depends_on_b)
    {
      logWarn("Circular frame dependency! Sampling will likely produce invalid results (sampling for groups '%s' and '%s')",
              a->getJointModelGroup()->getName().c_str(), b->getJointModelGroup()->getName().c_str());
      return true;
    }
    if (b_depends_on_a && !a_depends_on_b)
      return true;
    if(a_depends_on_b && !b_depends_on_a)
      return false;

    // prefer sampling JointConstraints first
    JointConstraintSampler *ja = dynamic_cast<JointConstraintSampler*>(a.get());
    JointConstraintSampler *jb = dynamic_cast<JointConstraintSampler*>(b.get());
    if (ja && jb == NULL)
      return true;
    if (jb && ja == NULL)
      return false;

    // neither depends on either, so break ties based on group name
    return (a->getJointModelGroup()->getName() < b->getJointModelGroup()->getName());
  }
/**
 * Expands the heap space by {KERNEL_HEAP_EXPAND_STEP} bytes.
 *
 * @return whether the operation was successful
 */
bool KernelHeap::expandHeap()
{
	// check limit
	if (heapEnd > CONST_KERNEL_HEAP_MAXIMUM_END)
	{
		logDebug("%! maximum reached during expansion", "kernheap");
		return false;
	}

	// Expand virtual space
	for (VirtualAddress virt = heapEnd; virt < heapEnd + KERNEL_HEAP_EXPAND_STEP; virt = virt + PAGE_SIZE)
	{
		// get a new physical page
		PhysicalAddress page = PPallocator::allocate();
		if (!page)
		{
			logWarn("%! no pages left for expanding", "kernheap");
			return false;
		}

		// map the page
		AddressSpace::map(virt, page, DEFAULT_KERNEL_TABLE_FLAGS, DEFAULT_KERNEL_PAGE_FLAGS);
	}

	// Create header
	allocator.expand(KERNEL_HEAP_EXPAND_STEP);
	heapEnd = heapEnd + KERNEL_HEAP_EXPAND_STEP;

	logDebug("%! expanded to end %h (%ikb in use)", "kernheap", heapEnd, usedMemoryAmount / 1024);
	return true;
}
bool robot_model::FloatingJointModel::normalizeRotation(std::vector<double> &values) const
{ 
  // normalize the quaternion if we need to
  double normSqr = values[3] * values[3] + values[4] * values[4] + values[5] * values[5] + values[6] * values[6];
  if (fabs(normSqr - 1.0) > std::numeric_limits<double>::epsilon() * 100.0)
  {
    double norm = sqrt(normSqr);
    if (norm < std::numeric_limits<double>::epsilon() * 100.0)
    {
      logWarn("Quaternion is zero in RobotState *representation. Setting to identity");
      values[3] = 0.0;
      values[4] = 0.0;
      values[5] = 0.0;
      values[6] = 1.0;
    }
    else
    {
      values[3] /= norm;
      values[4] /= norm;
      values[5] /= norm;
      values[6] /= norm;
    }
    return true;
  }
  else
    return false;
}
Пример #16
0
/**
 * Read the CRT protocol header returning the length of the data field
 */
static int readHeader(int sd, void *buf)
{
	char *p = (char *) buf;

	int len;
	if ((len = recvBytes(sd, buf, CERT_HEADER_LEN)) <= 0)
		return len;

	if (p[0] != 'C' || p[1] != 'R' || p[2] != 'T') {
		logError("Bad MAGIC received in header\n");
		return -2;
	}
	if (p[3] != '0') {
		logError("Unknown protocol/request received in header\n");
		return -2;
	}
	certHeader_t *req = (certHeader_t *) buf;
	req->length = htonl(req->length);

	if (req->length == 0) {
		logWarn("Received header with data length = %d\n", req->length);
		return 0;
	}

	return req->length;
}
Пример #17
0
size_t sampleSourcePcmWrite(SampleSourcePcmData self, const SampleBuffer sampleBuffer) {
    size_t pcmSamplesWritten = 0;
    size_t numSamplesToWrite = (size_t)(sampleBuffer->numChannels * sampleBuffer->blocksize);

    if(self == NULL || self->fileHandle == NULL) {
        logCritical("Corrupt PCM data structure");
        return false;
    }

    if(self->dataBufferNumItems < (size_t)(sampleBuffer->numChannels * sampleBuffer->blocksize)) {
        self->dataBufferNumItems = (size_t)(sampleBuffer->numChannels * sampleBuffer->blocksize);
        self->interlacedPcmDataBuffer = (short*)realloc(self->interlacedPcmDataBuffer, sizeof(short) * self->dataBufferNumItems);
    }

    // Clear the PCM data buffer just to be safe
    memset(self->interlacedPcmDataBuffer, 0, sizeof(short) * self->dataBufferNumItems);

    sampleBufferGetPcmSamples(sampleBuffer, self->interlacedPcmDataBuffer, self->isLittleEndian != isHostLittleEndian());
    pcmSamplesWritten = fwrite(self->interlacedPcmDataBuffer, sizeof(short), numSamplesToWrite, self->fileHandle);
    if(pcmSamplesWritten < numSamplesToWrite) {
        logWarn("Short write to PCM file");
        return pcmSamplesWritten;
    }

    logDebug("Wrote %d samples to PCM file", pcmSamplesWritten);
    return pcmSamplesWritten;
}
Пример #18
0
void RenderThread::render(RenderRequest* req)
{
	logFiner(QString("RenderThread::render : req 0x%1").arg((long)req,0,16));
	if (req->type() == RenderRequest::Preview)
	{
		preview_request = req;
		// rendering a preview preempts everything except files and previews
		if (isRendering())
			switch (current_request->type())
			{
				case RenderRequest::Image:
				case RenderRequest::Queued:
					stopRendering();
				default:
					;
			}
	}
	else if (req->type() == RenderRequest::Image)
		image_request = req;

	else if (request_queue.contains(req))
		logWarn(QString("RenderThread::render : req 0x%1 already queued")
				.arg((long)req,0,16));
	else
	{
		logFine("RenderThread::render : queueing req %#x", (long)req);
		req->setFinished(false);
		rqueue_mutex.lock();
		request_queue.enqueue(req);
		rqueue_mutex.unlock();
	}
}
Пример #19
0
void LMS1xx::login()
{
  char buf[100];
  int result;
  sprintf(buf, "%c%s%c", 0x02, "sMN SetAccessMode 03 F4724744", 0x03);

  fd_set readset;
  struct timeval timeout;


  do   //loop until data is available to read
  {
    timeout.tv_sec = 1;
    timeout.tv_usec = 0;

    write(socket_fd_, buf, strlen(buf));

    FD_ZERO(&readset);
    FD_SET(socket_fd_, &readset);
    result = select(socket_fd_ + 1, &readset, NULL, NULL, &timeout);

  }
  while (result <= 0);

  int len = read(socket_fd_, buf, 100);
  if (buf[0] != 0x02)
    logWarn("invalid packet recieved");
  buf[len] = 0;
  logDebug("RX: %s", buf);
}
Пример #20
0
void LoggerBase::logWarnPrintf(const char* fname, const char* funcName, int lineNum, const char* msg, ...)
{
    va_list args;   va_start(args, msg);    char buff[256] = { 0 };
    vsnprintf(buff, sizeof(buff)-1, msg, args);

    logWarn(buff, fname, funcName, lineNum);
    va_end(args);
}
bool kinematic_constraints::OrientationConstraint::configure(const moveit_msgs::OrientationConstraint &oc)
{
  //clearing out any old data
  clear();

  link_model_ = kmodel_->getLinkModel(oc.link_name);
  if(!link_model_)
  {
    logWarn("Could not find link model for link name %s", oc.link_name.c_str());
    return false;
  }
  Eigen::Quaterniond q;
  tf::quaternionMsgToEigen(oc.orientation, q);
  if (fabs(q.norm() - 1.0) > 1e-3)
  {
    logWarn("Orientation constraint for link '%s' is probably incorrect: %f, %f, %f, %f. Assuming identity instead.", oc.link_name.c_str(),
            oc.orientation.x, oc.orientation.y, oc.orientation.z, oc.orientation.w);
    q = Eigen::Quaterniond(1.0, 0.0, 0.0, 0.0);
  }

  if (oc.header.frame_id.empty())
    logWarn("No frame specified for position constraint on link '%s'!", oc.link_name.c_str());

  if (tf_->isFixedFrame(oc.header.frame_id))
  {
    tf_->transformQuaternion(oc.header.frame_id, q, q);
    desired_rotation_frame_id_ = tf_->getTargetFrame();
    desired_rotation_matrix_ = Eigen::Matrix3d(q);
    desired_rotation_matrix_inv_ = desired_rotation_matrix_.inverse();
    mobile_frame_ = false;
  }
  else
  {
    desired_rotation_frame_id_ = oc.header.frame_id;
    desired_rotation_matrix_ = Eigen::Matrix3d(q);
    mobile_frame_ = true;
  }
  std::stringstream matrix_str;
  matrix_str << desired_rotation_matrix_;
  logDebug("The desired rotation matrix for link '%s' in frame %s is:\n%s", oc.link_name.c_str(), desired_rotation_frame_id_.c_str(), matrix_str.str().c_str());

  if (oc.weight <= std::numeric_limits<double>::epsilon())
  {
    logWarn("The weight on position constraint for link '%s' is near zero.  Setting to 1.0.", oc.link_name.c_str());
    constraint_weight_ = 1.0;
  }
  else
    constraint_weight_ = oc.weight;
  absolute_x_axis_tolerance_ = fabs(oc.absolute_x_axis_tolerance);
  if (absolute_x_axis_tolerance_ < std::numeric_limits<double>::epsilon())
    logWarn("Near-zero value for absolute_x_axis_tolerance");
  absolute_y_axis_tolerance_ = fabs(oc.absolute_y_axis_tolerance);
  if (absolute_y_axis_tolerance_ < std::numeric_limits<double>::epsilon())
    logWarn("Near-zero value for absolute_y_axis_tolerance");
  absolute_z_axis_tolerance_ = fabs(oc.absolute_z_axis_tolerance);
  if (absolute_z_axis_tolerance_ < std::numeric_limits<double>::epsilon())
    logWarn("Near-zero value for absolute_z_axis_tolerance");

  return link_model_ != NULL;
}
Пример #22
0
bool LedReader::doReads()
{
    int i, len;
    quint32 values;
    char val[16];
    int fd;

    values = 0;

    for (i = 0; i < NUM_LEDS; i++) {
        fd = open(qPrintable(m_ledSysPathBrightness.at(i)), O_RDONLY);

        if (fd < 0) {
            logWarn(QString("Error opening %1 : %2")
                    .arg(m_ledSysPathBrightness.at(i))
                    .arg(strerror(errno)));

            break;
        }

        memset(val, 0, sizeof(val));
        len = read(fd, val, 8);

        if (len < 1) {
            logWarn(QString("read error[%1]: len = %2 %3")
                    .arg(i).arg(len)
                    .arg(strerror(errno)));

            close(fd);
            break;
        }

        close(fd);

        if (val[0] == '1')
            values |= (1 << i);
    }

    if (i < NUM_LEDS)
        return false;

    emit newData(values);

    return true;
}
Пример #23
0
bool user_switch(const char* user, const char* pass) {
	char shell[256];
	char homedir[256];
	char uidString[256] = {0};
	long handle;
	gid_t gid;
	uid_t uid;

	if (user == NULL) {
		logError("Unable to start a pam session with a null user");
		return false;
	}

	handle = pam_auth("su", user, pass);
	if (handle == 0) {
		logWarn("Authentication failed for user '%s'", user);
		return false;
	}

	if (!pam_startSession(handle)) {
		logWarn("Failed to start a session with the user '%s'", user);
		return false;
	}

	if (! pam_setEnv(handle)) {
		logWarn("Failed to customize user environment for the user '%s'", user);
		return false;
	}

	if (! user_getINFO(user, &gid, &uid, shell, homedir)) {
		logError("Unable to get user information");
		return false;
	}

	str_sprintf(uidString, "%d", uid);

	setenv("SHELL", shell, 1);
	setenv("PATH", "/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin", 1);
	setenv("UID", uidString, 1);
	setenv("USER", user, 1);
	setenv("HOME", homedir, 1);

	return (user_setGID(gid) && user_setGroup(user, gid) && fs_setCurrentDir(homedir) && user_setUID(uid));
}
Пример #24
0
void IntValueEditor::restoreSettings()
{
	if (objectName().isEmpty())
		logWarn("IntValueEditor::restoreSettings : nameless object found");

	setSingleStep(QSettings().value(
		QString("intvalueeditor/%1/singlestep").arg(objectName()), singleStep()).toInt());

	default_step = singleStep();
}
Пример #25
0
void CFSClient::appClientReceiveE2E(int servicePort, SYNTRO_EHEAD *message, int length)
{
	if (servicePort != m_CFSPort) {
		logWarn(QString("Message received with incorrect service port %1").arg(servicePort));
		free(message);
		return;
	}

	m_CFSThread->postThreadMessage(SYNTRO_CFS_MESSAGE, length, message);
}
Пример #26
0
void ompl_interface::ModelBasedStateSpace::setTagSnapToSegment(double snap)
{
  if (snap < 0.0 || snap > 1.0)
    logWarn("Snap to segment for tags is a ratio. It's value must be between 0.0 and 1.0. Value remains as previously set (%lf)", tag_snap_to_segment_);
  else
  {
    tag_snap_to_segment_ = snap;
    tag_snap_to_segment_complement_ = 1.0 - tag_snap_to_segment_;
  }
}
Пример #27
0
static int _canHostDo(const char* pluginName, const char* canDoString) {
  boolByte supported = false;

  logDebug("Plugin '%s' asked if we can do '%s'", pluginName, canDoString);
  if(!strcmp(canDoString, EMPTY_STRING)) {
    logWarn("Plugin '%s' asked if we can do an empty string. This is probably a bug.", pluginName);
  }
  else if(!strcmp(canDoString, "sendVstEvents")) {
    supported = true;
  }
  else if(!strcmp(canDoString, "sendVstMidiEvent")) {
    supported = true;
  }
  else if(!strcmp(canDoString, "sendVstTimeInfo")) {
    supported = true;
  }
  else if(!strcmp(canDoString, "receiveVstEvents")) {
    supported = false;
  }
  else if(!strcmp(canDoString, "receiveVstMidiEvent")) {
    supported = false;
  }
  else if(!strcmp(canDoString, "reportConnectionChanges")) {
    supported = false;
  }
  else if(!strcmp(canDoString, "acceptIOChanges")) {
    supported = false;
  }
  else if(!strcmp(canDoString, "sizeWindow")) {
    supported = false;
  }
  else if(!strcmp(canDoString, "offline")) {
    supported = false;
  }
  else if(!strcmp(canDoString, "openFileSelector")) {
    supported = false;
  }
  else if(!strcmp(canDoString, "closeFileSelector")) {
    supported = false;
  }
  else if(!strcmp(canDoString, "startStopProcess")) {
    supported = true;
  }
  else if(!strcmp(canDoString, "shellCategory")) {
    supported = true;
  }
  else if(!strcmp(canDoString, "sendVstMidiEventFlagIsRealtime")) {
    supported = false;
  }
  else {
    logInfo("Plugin '%s' asked if host canDo '%s' (unimplemented)", pluginName, canDoString);
  }
  
  return supported;
}
rviz::BoolProperty* moveit_rviz_plugin::PerLinkObjBase::getBoolProperty(
      const std::string& name)
{
  rviz::BoolProperty *p = NULL;
  std::map<std::string, rviz::Property*>::iterator it = extra_property_map_.find(name);
  if (it != extra_property_map_.end())
    p = dynamic_cast<rviz::BoolProperty*>(it->second);
  if (!p)
    logWarn("No bool property '%s' found",name.c_str());
  return p;
}
Пример #29
0
// Factory :
ElementContainer* ElementContainer::create(Type type)
{
	switch(type)
	{
	case ARRAY:
		return new ArrayElementContainer();
	default:
		logWarn("element container type \"", getTypeStr(type), "\" not implemented, will probably crash !");
		return NULL;
	}
}
Пример #30
0
static void _remapFileToErrorReport(ErrorReporter errorReporter, ProgramOption option, boolByte copyFile) {
  if(option->enabled) {
    if(copyFile) {
      // TODO: Slight abuse of private field, probably should avoid doing that...
      if(!errorReportCopyFileToReport(errorReporter, option->_data.string)) {
        logWarn("Failed copying '%s' to error report directory, please include this file manually",
          option->_data.string->data);
      }
    }
    errorReporterRemapPath(errorReporter, option->_data.string);
  }
}