Example #1
0
vector<LpmEntry> LpmConfigurationReaderV1::readLpmEntries(void)
{
    vector<LpmEntry> lpmEntries;

    string target;
    DomainType::Type domainType;
    ControlKnobType::Type controlKnob;
    UInt32 controlValue;

    UIntN lpmEntryIndex;
    string inputKeyPath = keyPath();
    try
    {
        for (lpmEntryIndex = 0; ; lpmEntryIndex++)
        {
            setLpmEntryKeyPath(inputKeyPath, lpmEntryIndex);

            target = readTargetDeviceAcpiScope();
            domainType = readDomainType();
            controlKnob = readControlKnob();
            controlValue = readControlValue();
            
            lpmEntries.push_back(LpmEntry(target, domainType, controlKnob, controlValue));
            if (lpmEntryIndex >= LpmEntriesIndexLimit::MaxLpmEntryIndex)
            {
                throw dptf_exception("LPM entries exceeded max value");
            }
        }
    }
    catch (dptf_exception& e)
    {
        string msg = e.what();
        postInfoMessage(PolicyMessage(FLF,
            "Error msg (" + msg + "). Last lpmEntryIndex = " + to_string(lpmEntryIndex),
            Constants::Invalid));
        return lpmEntries;
    }

    return (lpmEntries);
}
void CamConfig::readControl(struct v4l2_queryctrl& queryctrl_tmp) {
    LOG_DEBUG("CamConfig: readControl %d", queryctrl_tmp.id);

    // Store control id because it could be changed by the driver.
    unsigned int original_control_id = queryctrl_tmp.id;

    // Control-request successful?
    if (0 == ioctl (mFd, VIDIOC_QUERYCTRL, &queryctrl_tmp)) {
        // Control available by the camera (continue if not)?
        if (queryctrl_tmp.flags & V4L2_CTRL_FLAG_DISABLED) {
            LOG_INFO("Control id %d marked as disabled", original_control_id);
            return;
        }

        // Driver seems not to like the control.
        if (queryctrl_tmp.id != original_control_id) {
            LOG_INFO("Driver has changed the control ID %d, will not be used", original_control_id);
            return;
        }

        // Create and fill CamCtrl object.
        CamCtrl cam_ctrl;
        cam_ctrl.mCtrl = queryctrl_tmp;

        // Read-only control?
        // Flags V4L2_CTRL_FLAG_GRABBED, V4L2_CTRL_FLAG_UPDATE, V4L2_CTRL_FLAG_INACTIVE
        // and V4L2_CTRL_FLAG_SLIDER are ignored at the moment.
        if (queryctrl_tmp.flags & V4L2_CTRL_FLAG_READ_ONLY) {
            LOG_INFO("Control %s(%d) marked as read-only", cam_ctrl.mCtrl.name, original_control_id);
            cam_ctrl.mWriteable = false;
            return;
        }

        // Read menue entries if available.
        if (queryctrl_tmp.type == V4L2_CTRL_TYPE_MENU) {
            struct v4l2_querymenu querymenu_tmp;
            memset (&querymenu_tmp, 0, sizeof (struct v4l2_querymenu));
            querymenu_tmp.id = queryctrl_tmp.id;

            // Store menu item names if the type of the control is a menu. 
            for (int i = queryctrl_tmp.minimum; i <= queryctrl_tmp.maximum; ++i) {
                querymenu_tmp.index = (uint32_t)i;
                if (0 == ioctl (mFd, VIDIOC_QUERYMENU, &querymenu_tmp)) {
                    // Store names of the menu items.
                    char buffer[32];
                    snprintf(buffer, 32, "%s", querymenu_tmp.name);
                    cam_ctrl.mMenuItems.push_back(buffer);
                    LOG_DEBUG(" - menu entry %s", buffer);
                } else {
                    std::string err_str(strerror(errno));
                    throw std::runtime_error(err_str.insert(0, 
                        "Could not read menu item: "));
                }
            }
        }
        
        // Store CamCtrl using control ID as key. Use returned iterator
        // to set readable and writeable.
        std::pair<std::map<uint32_t, struct CamCtrl>::iterator, bool> ret = 
                mCamCtrls.insert(std::pair<int32_t,struct CamCtrl>(original_control_id, cam_ctrl));
        std::map<uint32_t, struct CamCtrl>::iterator it = ret.first;

        // Read and store current value.
        try {
            cam_ctrl.mValue = readControlValue(original_control_id);
        } catch(std::runtime_error& e) {
            // Assuming write-only control (id valid, only write operation should work)
            LOG_WARN("Control %s (%d) seems not to be readable: %s", 
                     cam_ctrl.mCtrl.name, original_control_id, e.what());
            it->second.mReadable = false;
        }

        // Try writing the current value back
        if (it->second.mWriteable)
        {
            try {
                writeControlValue(original_control_id, cam_ctrl.mValue, true);
            } catch(std::runtime_error& e) {
                // Assuming read-only control (id valid, only read operation should work)
                LOG_WARN("Control %s (%d) seems not to be writeable: %s", 
                         cam_ctrl.mCtrl.name, original_control_id, e.what());
                
                // Absolute control values like Exposure or Focus can only be changed
                // in Manual Mode. They will not be set to not-writeable here.
                if(mAutoManualDependentControlIds.find(original_control_id) == 
                        mAutoManualDependentControlIds.end()) { 
                    it->second.mWriteable = false;
                }
            }
        }
    } else {
        // Unknown control, will be ignored.
        if (errno == EINVAL) { 
            LOG_DEBUG("Control %d not available and will be ignored", original_control_id);
            return;
        }
        std::string err_str(strerror(errno)); 
        throw std::runtime_error(err_str.insert(0, "Could not query control: ")); 
    }
}