void ServoDynamixel::setMaxTorque(int torque)
{
    //std::cout << "[#" << servoId << "] setMaxTorque(" << torque << ")" << std::endl;

    if (torque < 1024)
    {
        std::lock_guard <std::mutex> lock(access);

        registerTableValues[gid(REG_MAX_TORQUE)] = torque;
        registerTableCommits[gid(REG_MAX_TORQUE)] = 1;
    }
}
void ServoDynamixel::setCCWLimit(int limit)
{
    //std::cout << "[#" << servoId << "] setCCWLimit(" << limit << ")" << std::endl;

    if (limit > -1 && limit < steps)
    {
        std::lock_guard <std::mutex> lock(access);

        registerTableValues[gid(REG_MAX_POSITION)] = limit;
        registerTableCommits[gid(REG_MAX_POSITION)] = 1;
    }
}
void ServoDynamixel::setTorqueEnabled(int torque)
{
    // Normalize value
    (torque > 0) ? torque = 1 : torque = 0;

    //std::cout << "[#" << servoId << "] setTorqueEnabled(" << torque << ")" << std::endl;

    std::lock_guard <std::mutex> lock(access);

    registerTableValues[gid(REG_TORQUE_ENABLE)] = torque;
    registerTableCommits[gid(REG_TORQUE_ENABLE)] = 1;
}
void ServoDynamixel::setId(int id)
{
    //std::cout << "[#" << servoId << "] setId(from " << servoId << " to " << id << ")" << std::endl;

    if (id > -1 && id < 254)
    {
        std::lock_guard <std::mutex> lock(access);

        // Maybe check if new ID is not already in use ?
        registerTableValues[gid(REG_ID)] = id;
        registerTableCommits[gid(REG_ID)] = 1;
    }
}
double ServoDynamixel::getCurrentVoltage()
{
    std::lock_guard <std::mutex> lock(access);
    int ivolt = registerTableValues[gid(REG_CURRENT_VOLTAGE)];

    return (ivolt / 10.0);
}
double ServoDynamixel::getHighestLimitVolt()
{
    std::lock_guard <std::mutex> lock(access);
    int volt = registerTableValues[gid(REG_VOLTAGE_HIGHEST_LIMIT)];

    return (volt / 10.0);
}
void ServoDynamixel::getModelInfos(int &servo_serie, int &servo_model)
{
    std::lock_guard <std::mutex> lock(access); // ?
    int model_number = registerTableValues[gid(REG_MODEL_NUMBER)];

    dxl_get_model_infos(model_number, servo_serie, servo_model);
}
/*!
  Change the file owner for the log locations.
 */
void XmlVhostHandler::changeLocationsOwner ()
{
  if (Server::getInstance ()->getUid ()
      || Server::getInstance ()->getGid ())
    {
      string uid (Server::getInstance ()->getUid ());
      string gid (Server::getInstance ()->getGid ());

      /*
       *Change the log files owner if a different user or group
       *identifier is specified.
       */
      for (vector<Vhost*>::iterator it = hosts.begin (); it != hosts.end (); it++)
        {
          int err;
          Vhost* vh = *it;

          /* Chown the log files.  */
          err = logManager->chown (vh, "ACCESSLOG", uid, gid);
          if (err)
            Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
                    _("Error while changing accesses log owner"));

          err = logManager->chown (vh, "WARNINGLOG", uid, gid);
          if (err)
            Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
                    _("Error while changing warnings log owner"));
        }
    }
}
int SocketInfo::Create(const std::string& context) const {
    auto types = android::base::Split(type(), "+");
    int flags =
        ((types[0] == "stream" ? SOCK_STREAM : (types[0] == "dgram" ? SOCK_DGRAM : SOCK_SEQPACKET)));
    bool passcred = types.size() > 1 && types[1] == "passcred";
    return CreateSocket(name().c_str(), flags, passcred, perm(), uid(), gid(), context.c_str());
}
Beispiel #10
0
naming::gid_type component_storage::migrate_to_here(
    std::vector<char> const& data, naming::id_type id,
    naming::address const& current_lva)
{
    naming::gid_type gid(naming::detail::get_stripped_gid(id.get_gid()));
    data_[gid] = data;

    // rebind the object to this storage locality
    naming::address addr(current_lva);
    addr.address_ = 0;       // invalidate lva
    if (!agas::bind(launch::sync, gid, addr, this->gid_))
    {
        std::ostringstream strm;
        strm << "failed to rebind id " << id
             << "to storage locality: " << gid_;

        HPX_THROW_EXCEPTION(duplicate_component_address,
                            "component_storage::migrate_to_here",
                            strm.str());
        return naming::invalid_gid;
    }

    id.make_unmanaged();            // we can now release the object
    return naming::invalid_gid;
}
  void testChown ()
  {
#ifndef WIN32
    list<string> filters;

    try
      {
        FilesUtility::deleteFile ("foo");
      }
    catch (...)
      {
      }


    lm->add (this, "test", "file://foo", filters, 0);
    ostringstream uidOss;
    uidOss << ::getuid ();
    string uid (uidOss.str ());

    ostringstream gidOss;
    gidOss << ::getuid ();
    string gid (gidOss.str ());

    CPPUNIT_ASSERT (!lm->chown (this, "test", "file://foo", uid, gid));
#endif
  }
ServoDynamixel::ServoDynamixel(const int control_table[][8], int dynamixel_id, int dynamixel_model, int speed_mode):
    Servo()
{
    // Store servo id, serie and model
    servoId = dynamixel_id;
    dxl_get_model_infos(dynamixel_model, servoSerie, servoModel);

    // Set the control table
    if (control_table)
    {
        ct = control_table;
    }
    else
    {
        ct = MX_control_table;
    }

    // Register count // FIXME // Horrible hack!
    for (registerTableSize = 0; registerTableSize < 64; registerTableSize++)
    {
        if (ct[registerTableSize][0] == 999) // end of table
        {
            break;
        }
    }

    // Init register tables (value and commit info) with value-initialization
    registerTableValues = new int [registerTableSize]();
    registerTableCommits = new int [registerTableSize]();

    // Set model and id because we already known them
    registerTableValues[gid(REG_MODEL_NUMBER)] = dynamixel_model;
    if (dynamixel_id > -1 && dynamixel_id < BROADCAST_ID)
    {
        registerTableValues[gid(REG_ID)] = dynamixel_id;
    }

    // Choose speed mode
    if (speed_mode == SPEED_MANUAL || speed_mode == SPEED_AUTO)
    {
        speedMode = speed_mode;
    }

    // Set default value for ack policy, ACK_REPLY_ALL for Dynamixel devices
    // (will be overwritten when reading the real value from the device)
    registerTableValues[gid(REG_STATUS_RETURN_LEVEL)] = ACK_REPLY_ALL;
}
Beispiel #13
0
bool KUserGroup::operator ==(const KUserGroup& group) const {
  if (isValid() != group.isValid())
    return false;
  if (isValid())
    return gid() == group.gid();
  else
    return true;
}
void ServoDynamixel::setGoalPosition(int pos)
{
    //std::cout << "[#" << servoId << "] DXL setGoalPosition(" << pos << ")" << std::endl;

    if (pos > -1 && pos < steps)
    {
        std::lock_guard <std::mutex> lock(access);

        // Check min/max positions
        if (pos < registerTableValues[gid(REG_MIN_POSITION)])
        {
            pos = registerTableValues[gid(REG_MIN_POSITION)];
        }
        if (pos > registerTableValues[gid(REG_MAX_POSITION)])
        {
            pos = registerTableValues[gid(REG_MAX_POSITION)];
        }

        // Set position
        registerTableValues[gid(REG_GOAL_POSITION)] = pos;
        registerTableCommits[gid(REG_GOAL_POSITION)] = 1;
    }
    else
    {
        std::cerr << "[#" << servoId << "] setGoalPosition(" << registerTableValues[gid(REG_CURRENT_POSITION)] << " > " << pos << ") [VALUE ERROR]" << std::endl;
    }
}
void ServoDynamixel::setLed(int led)
{
    //std::cout << "[#" << servoId << "] setLed(" << led << ")" << std::endl;
    std::lock_guard <std::mutex> lock(access);

    // Normalize value
    if (led >= 1)
    {
        (servoSerie == SERVO_XL) ? led = led : led = 1;
    }
    else
    {
        led = 0;
    }

    registerTableValues[gid(REG_LED)] = led;
    registerTableCommits[gid(REG_LED)] = 1;
}
void ServoDynamixel::setGoalPosition(int pos, int time_budget_ms)
{
    //std::cout << "[#" << servoId << "] DXL setGoalPosition(" << pos << " in " << time_budget_ms <<  "ms)" << std::endl;

    if (time_budget_ms > 0)
    {
        if (pos > -1 && pos < steps)
        {
            std::lock_guard <std::mutex> lock(access);

            // Check min/max positions
            if (pos < registerTableValues[gid(REG_MIN_POSITION)])
            {
                pos = registerTableValues[gid(REG_MIN_POSITION)];
            }
            if (pos > registerTableValues[gid(REG_MAX_POSITION)])
            {
                pos = registerTableValues[gid(REG_MAX_POSITION)];
            }

            // Compute movment amplitude and necessary speed to meet time budget
            int amp = 0;
            int pos_curr = registerTableValues[gid(REG_CURRENT_POSITION)];

            if (pos > pos_curr)
                amp = pos - pos_curr;
            else
                amp = pos_curr - pos;

            double speed = ((double)(60 * amp) / (double)(steps * 0.114 * ((double)(time_budget_ms)/1000.0)));
            if (speed < 1.0)
                speed = 1;

            // Set position and speed
            registerTableValues[gid(REG_GOAL_POSITION)] = pos;
            registerTableCommits[gid(REG_GOAL_POSITION)] = 1;

            registerTableValues[gid(REG_GOAL_SPEED)] = speed;
            registerTableCommits[gid(REG_GOAL_SPEED)] = 1;
        }
        else
        {
            std::cerr << "[#" << servoId << "] setGoalPosition(" << registerTableValues[gid(REG_CURRENT_POSITION)] << " > " << pos << ") [VALUE ERROR]" << std::endl;
        }
    }
}
void ServoDynamixel::waitMovmentCompletion(int timeout_ms)
{
    std::chrono::milliseconds timeout_duration(static_cast<int>(timeout_ms));
    std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();

    access.lock();

    int c = registerTableValues[gid(REG_CURRENT_POSITION)];
    int g = registerTableValues[gid(REG_GOAL_POSITION)];

    // Margin is set to 3% of servo steps
    int margin = static_cast<int>(static_cast<double>(steps) * 0.03 / 2.0);
    int margin_up = g + margin;
    int margin_dw = g - margin;

    if (margin_up > steps) margin_up = steps;
    if (margin_dw < 0) margin_dw = 0;

    // Wait until the current pos is within margin of the goal pos, or wait for the timeout
    while (!(c < margin_up && c > margin_dw))
    {
        access.unlock();

        //std::cout << "waitMovmentCompletion (" << margin_dw << " <  pos:" << c << "  < " << margin_up << ")" << std::endl;

        if ((start + timeout_duration) < std::chrono::system_clock::now())
        {
            std::cerr << "waitMovmentCompletion(): timeout!" << std::endl;
            return;
        }

        std::chrono::milliseconds loopwait(4);
        std::this_thread::sleep_for(loopwait);

        access.lock();

        c = registerTableValues[gid(REG_CURRENT_POSITION)];
        g = registerTableValues[gid(REG_GOAL_POSITION)];
    }
    access.unlock();
}
Beispiel #18
0
void MyDirEntry::setMetadata(const QString& path) const{
    QFile file(path);
    file.setPermissions(permissions);
    
    struct timeval tv[2];
    tv[0].tv_sec=lastModified.toTime_t();
    tv[0].tv_usec=0;
    tv[1].tv_sec=lastModified.toTime_t();
    tv[1].tv_usec=0;
    lutimes(QFile::encodeName(file.fileName()), tv);
    lchown(QFile::encodeName(file.fileName()), uid(), gid());
}
void ServoDynamixel::moveGoalPosition(int move)
{
    //std::cout << "moveGoalPosition(" << move << ")" << std::endl;
    access.lock();

    int curr = registerTableValues[gid(REG_CURRENT_POSITION)];
    int newpos = registerTableValues[gid(REG_CURRENT_POSITION)] + move;

    // Wheel mode ?
    if (registerTableValues[gid(REG_MIN_POSITION)] == 0 && registerTableValues[gid(REG_MAX_POSITION)] == 0)
    {
        if (newpos < 0 || newpos > steps)
        {
            int mod = newpos % steps;

            std::cerr << "[#" << servoId << "]  moveGoalPosition([" << curr << " > " << newpos << "] [VALUE ERROR] with modulo: " << mod <<  std::endl;
        }
    }

    access.unlock();

    setGoalPosition(newpos);
}
Beispiel #20
0
    /// \brief Shutdown the given runtime system
    lcos::future<void>
    runtime_support::shutdown_async(naming::id_type const& targetgid,
        double timeout)
    {
        // Create a promise directly and execute the required action.
        // This action has implemented special response handling as the
        // back-parcel is sent explicitly (and synchronously).
        typedef server::runtime_support::shutdown_action action_type;

        lcos::promise<void> value;
        // We need to make it unmanaged to avoid late refcnt requests
        id_type gid(value.get_id().get_gid(), id_type::unmanaged);
        hpx::apply<action_type>(targetgid, timeout, gid);
        return value.get_future();
    }
Beispiel #21
0
void CreateMCFThread::processGames(std::vector<UserCore::Item::BranchInfo*> &outList, TiXmlElement* platform)
{
	XML::for_each_child("game", platform->FirstChildElement("games"), [this, &outList](TiXmlElement* game)
	{
		const char* szId = game->Attribute("siteareaid");
		DesuraId gid(szId, "games");

		if (gid == this->getItemId())
			this->processBranches(outList, game);
	
		if (this->getItemId().getType() != DesuraId::TYPE_MOD)
			return;

		this->processMods(outList, game);
	});
}
Beispiel #22
0
bool unregister_name(
    std::string const& name
  , error_code& ec
    )
{
    naming::resolver_client& agas_ = naming::get_agas_client();

    naming::gid_type raw_gid;

    if (agas_.unregister_name(name, raw_gid, ec) && !ec)
    {
        // If the GID has a reference count, return it to AGAS.
        if (naming::get_credit_from_gid(raw_gid) != 0)
            // When this id_type goes out of scope, it's deleter will
            // take care of the reference count.
            naming::id_type gid(raw_gid, naming::id_type::managed);

        return true;
    }

    return false;
}
Beispiel #23
0
static bool
gid_alloc (gid_t *gidp, uid_t uid)
{
  str path (sfssockdir << "/agent.sock");
  int fd = unixsocket_connect (path);
  if (fd < 0) {
    warn << path << ": " << strerror (errno) << "\n";
    return false;
  }
  close_on_exec (fd);

  AUTH *auth = authunixint_create ("localhost", uid, getgid (), 0, NULL);
  if (!auth)
    fatal ("could not create RPC authunix credentials\n");

  int32_t res (EIO);
  srpc_callraw (fd, SETUID_PROG, SETUID_VERS, SETUIDPROC_SETUID,
		xdr_void, NULL, xdr_int32_t, &res, auth);
  if (res) {
    close (fd);
    warn ("sfscd rejected credentials: %s\n", strerror (errno));
    return false;
  }

  u_int32_t gid (static_cast<u_int32_t> (sfs_badgid));
  clnt_stat stat = srpc_callraw (fd, AGENT_PROG, AGENT_VERS, AGENT_AIDALLOC,
				 xdr_void, NULL, xdr_u_int32_t, &gid, NULL);
  close (fd);
  if (stat || gid < sfs_resvgid_start
      || gid >= (sfs_resvgid_start + sfs_resvgid_count)) {
    warn << "no free group IDs.\n";
    return false;
  }
  *gidp = static_cast<gid_t> (gid);
  return true;
}
void ServoDynamixel::setMovingSpeed(int speed)
{
    //std::cout << "setMovingSpeed(" << speed << ")" << std::endl;
    std::lock_guard <std::mutex> lock(access);

    if (registerTableValues[gid(REG_MIN_POSITION)] == 0 &&
        registerTableValues[gid(REG_MAX_POSITION)] == 0)
    {
        if (speed < 2048)
        {
            registerTableValues[gid(REG_GOAL_SPEED)] = speed;
            registerTableCommits[gid(REG_GOAL_SPEED)] = 1;
        }
    }
    else
    {
        if (speed < 1024)
        {
            registerTableValues[gid(REG_GOAL_SPEED)] = speed;
            registerTableCommits[gid(REG_GOAL_SPEED)] = 1;
        }
    }
}
Beispiel #25
0
 //! Returns true if the LID passed in belongs to the calling processor in this map, otherwise returns false.
 bool  myLID( size_type LID ) const
 {
     return( gid( LID )!=invalid_size_type_value );
 }
Beispiel #26
0
bool KUserGroup::isValid() const {
	return gid() != gid_t(-1);
}
Beispiel #27
0
bool KUserGroup::operator !=(const KUserGroup& user) const {
	return (gid() != user.gid()) || (gid() == gid_t(-1));
}
Beispiel #28
0
bool KUserGroup::operator ==(const KUserGroup& group) const {
	return (gid() == group.gid()) && (gid() != gid_t(-1));
}
Beispiel #29
0
static void Test_make_temporary_oneshot_service(bool dash_dash, bool seclabel, bool uid, bool gid,
                                                bool supplementary_gids) {
    std::vector<std::string> args;
    args.push_back("exec");
    if (seclabel) {
        args.push_back("u:r:su:s0");  // seclabel
        if (uid) {
            args.push_back("log");  // uid
            if (gid) {
                args.push_back("shell");  // gid
                if (supplementary_gids) {
                    args.push_back("system");  // supplementary gid 0
                    args.push_back("adb");     // supplementary gid 1
                }
            }
        }
    }
    if (dash_dash) {
        args.push_back("--");
    }
    args.push_back("/system/bin/toybox");
    args.push_back("id");
    auto svc = Service::MakeTemporaryOneshotService(args);
    ASSERT_NE(nullptr, svc);

    if (seclabel) {
        ASSERT_EQ("u:r:su:s0", svc->seclabel());
    } else {
        ASSERT_EQ("", svc->seclabel());
    }
    if (uid) {
        auto decoded_uid = DecodeUid("log");
        ASSERT_TRUE(decoded_uid);
        ASSERT_EQ(*decoded_uid, svc->uid());
    } else {
        ASSERT_EQ(0U, svc->uid());
    }
    if (gid) {
        auto decoded_uid = DecodeUid("shell");
        ASSERT_TRUE(decoded_uid);
        ASSERT_EQ(*decoded_uid, svc->gid());
    } else {
        ASSERT_EQ(0U, svc->gid());
    }
    if (supplementary_gids) {
        ASSERT_EQ(2U, svc->supp_gids().size());

        auto decoded_uid = DecodeUid("system");
        ASSERT_TRUE(decoded_uid);
        ASSERT_EQ(*decoded_uid, svc->supp_gids()[0]);

        decoded_uid = DecodeUid("adb");
        ASSERT_TRUE(decoded_uid);
        ASSERT_EQ(*decoded_uid, svc->supp_gids()[1]);
    } else {
        ASSERT_EQ(0U, svc->supp_gids().size());
    }

    ASSERT_EQ(static_cast<std::size_t>(2), svc->args().size());
    ASSERT_EQ("/system/bin/toybox", svc->args()[0]);
    ASSERT_EQ("id", svc->args()[1]);
}
void ServoDynamixel::status()
{
    std::lock_guard <std::mutex> lock(access);

    std::cout << "Status(#" << servoId << ")" << std::endl;

    std::cout << "> model      : " << servoModel << std::endl;
    std::cout << "> firmware   : " << registerTableValues[gid(REG_FIRMWARE_VERSION)] << std::endl;
    std::cout << "> baudrate   : " << dxl_get_baudrate(registerTableValues[gid(REG_BAUD_RATE)]) << std::endl;

    std::cout << ">> speed mode     : " << speedMode << std::endl;
    std::cout << ">> steps          : " << steps << std::endl;
    std::cout << ">> runningDegrees : " << runningDegrees << std::endl;

    std::cout << "> torque enabled  : " << registerTableValues[gid(REG_TORQUE_ENABLE)] << std::endl;
    std::cout << "> max torque      : " << registerTableValues[gid(REG_MAX_TORQUE)] << std::endl;
    std::cout << "> torque limit    : " << registerTableValues[gid(REG_TORQUE_LIMIT)] << std::endl;

    std::cout << "> goal position   : " << registerTableValues[gid(REG_GOAL_POSITION)] << std::endl;
    std::cout << "> goal speed      : " << registerTableValues[gid(REG_GOAL_SPEED)] << std::endl;
    std::cout << "> current position: " << registerTableValues[gid(REG_CURRENT_POSITION)] << std::endl;
    std::cout << "> current speed   : " << registerTableValues[gid(REG_CURRENT_SPEED)] << std::endl;
    std::cout << "> current load    : " << registerTableValues[gid(REG_CURRENT_LOAD)] << std::endl;
    std::cout << "> current voltage : " << registerTableValues[gid(REG_CURRENT_VOLTAGE)] << std::endl;
    std::cout << "> current temp    : " << registerTableValues[gid(REG_CURRENT_TEMPERATURE)] << std::endl;
    std::cout << "> registered      : " << registerTableValues[gid(REG_REGISTERED)] << std::endl;
    std::cout << "> moving          : " << registerTableValues[gid(REG_MOVING)] << std::endl;
    std::cout << "> lock            : " << registerTableValues[gid(REG_LOCK)] << std::endl;
    std::cout << "> punch           : " << registerTableValues[gid(REG_PUNCH)] << std::endl;
}