Exemple #1
0
bool sHotKeyOpts::Write(Setting& cProfile)
{
	Setting* s;
	std::string hk("Start");
	if(cProfile.exists(hk)) {
		s = &(cProfile[hk]);
	} else
		s = &(cProfile.add(hk, Setting::TypeGroup));
	UpdateSetting(*s, "Key", (int&)m_RecordStart.m_vKey, Setting::TypeInt);
	UpdateSetting(*s, "Mod", (int&)m_RecordStart.m_fsMod, Setting::TypeInt);

	hk = "End";
	if(cProfile.exists(hk)) {
		s = &(cProfile[hk]);
	} else
		s = &(cProfile.add(hk, Setting::TypeGroup));
	UpdateSetting(*s, "Key", (int&)m_RecordEnd.m_vKey, Setting::TypeInt);
	UpdateSetting(*s, "Mod", (int&)m_RecordEnd.m_fsMod, Setting::TypeInt);

	hk = "Cancel";
	if(cProfile.exists(hk)) {
		s = &(cProfile[hk]);
	} else
		s = &(cProfile.add(hk, Setting::TypeGroup));
	UpdateSetting(*s, "Key", (int&)m_RecordCancel.m_vKey, Setting::TypeInt);
	UpdateSetting(*s, "Mod", (int&)m_RecordCancel.m_fsMod, Setting::TypeInt);

	hk = "Next";
	if(cProfile.exists(hk)) {
		s = &(cProfile[hk]);
	} else
		s = &(cProfile.add(hk, Setting::TypeGroup));
	UpdateSetting(*s, "Key", (int&)m_Next.m_vKey, Setting::TypeInt);
	UpdateSetting(*s, "Mod", (int&)m_Next.m_fsMod, Setting::TypeInt);

	hk = "Prev";
	if(cProfile.exists(hk)) {
		s = &(cProfile[hk]);
	} else
		s = &(cProfile.add(hk, Setting::TypeGroup));
	UpdateSetting(*s, "Key", (int&)m_Prev.m_vKey, Setting::TypeInt);
	UpdateSetting(*s, "Mod", (int&)m_Prev.m_fsMod, Setting::TypeInt);

	hk = "Layout";
	if(cProfile.exists(hk)) {
		s = &(cProfile[hk]);
	} else
		s = &(cProfile.add(hk, Setting::TypeGroup));
	UpdateSetting(*s, "Key", (int&)m_ShowLayout.m_vKey, Setting::TypeInt);
	UpdateSetting(*s, "Mod", (int&)m_ShowLayout.m_fsMod, Setting::TypeInt);

	hk = "Zoom";
	if(cProfile.exists(hk)) {
		s = &(cProfile[hk]);
	} else
		s = &(cProfile.add(hk, Setting::TypeGroup));
	UpdateSetting(*s, "Key", (int&)m_Zoom.m_vKey, Setting::TypeInt);
	UpdateSetting(*s, "Mod", (int&)m_Zoom.m_fsMod, Setting::TypeInt);
	return true;
}
Exemple #2
0
void WriteTA(Setting& s, TextAttributes& taResult)
{
	UpdateSetting(s,"position", (int&)taResult.position, Setting::TypeInt);
	UpdateSetting(s,"posType", (int&)taResult.posType, Setting::TypeInt);
	UpdateSetting(s,"xPosRatio", taResult.xPosRatio, Setting::TypeInt);
	UpdateSetting(s,"yPosRatio", taResult.yPosRatio, Setting::TypeInt);
	std::string text(taResult.text);
	UpdateSetting(s,"text", text, Setting::TypeString);
	UpdateSetting(s,"backgroundColor", (int&)taResult.backgroundColor, Setting::TypeInt);
	UpdateSetting(s,"textColor", (int&)taResult.textColor, Setting::TypeInt);
	UpdateSetting(s,"isFontSelected", taResult.isFontSelected, Setting::TypeInt);
	Setting* sf;
	if (s.exists("Font"))
		sf = &(s["Font"]);
	else
		sf = &(s.add("Font", Setting::TypeGroup));
	WriteFont(*sf, taResult.logfont);
}
Exemple #3
0
bool AVConfig::Init()
{
	int video_device = NULL;
	const char *device_name;
	struct stat st;

	//check if there're essential settings
	if(!getRoot()->exists("audio"))
		getRoot()->add("audio", Setting::TypeGroup);
	if(!getRoot()->exists("video"))
		getRoot()->add("video", Setting::TypeGroup);

	//open video device
	if(!getVideoSettings()->exists("device"))
		getVideoSettings()->add("device", Setting::TypeString) = "/dev/video0";
	device_name = (*getVideoSettings())["device"];
	if(-1 == stat(device_name, &st))
	{
		log_message(1, "AVConfig: Cannot identify '%s': %d, %s.", device_name, errno, strerror (errno));
		return false;
	}
	if(!S_ISCHR(st.st_mode))
	{
		log_message(1, "AVConfig: %s is no device.", device_name);
		return false;
	}

	video_device = open(device_name, O_RDWR | O_NONBLOCK, 0);
	if(-1 == video_device)
	{
		log_message(1, "AVConfig: Cannot open '%s': %d, %s.", device_name, errno, strerror (errno));
		exit (EXIT_FAILURE);
	}


	//determine video device capabilities
	v4l2_capability cap;
	if(-1 == xioctl(video_device, VIDIOC_QUERYCAP, &cap))
	{
		if (EINVAL == errno)
		{
			log_message(1, "AVConfig: %s is no V4L2 device.", device_name);
			exit(1);
		}
		else log_message(1, "AVConfig: VIDIOC_QUERYCAP: %d, %s.", errno, strerror(errno));
	}
	if(!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
	{
		log_message(1, "AVConfig: %s is no video capture device.", device_name);
		exit(1);
	}
	if(cap.capabilities & V4L2_CAP_READWRITE)
		log_message(0, "AVConfig: %s supports read i/o.", device_name);
	if(cap.capabilities & V4L2_CAP_STREAMING)
		log_message(0, "AVConfig: %s supports streaming i/o.", device_name);


	//enumerate inputs
	vector<v4l2_input> input_list;
	v4l2_input input;
	int current_input;
	CLEAR(input);
	input.index = 0;
	while(-1 != xioctl(video_device, VIDIOC_ENUMINPUT, &input))
	{
		input_list.push_back(input);
		log_message(0, "AVConfig: Input [%d -- %s] is found.", input.index, input.name);
		input.index++;
	}
	if(-1 == xioctl(video_device, VIDIOC_G_INPUT, &current_input))
	{
		log_errno("AVConfig: VIDIOC_G_INPUT");
		exit(1);
	}
	log_message(0, "AVConfig: Currently selected input is: %d -- %s.", current_input, input_list[current_input].name);


	//enumerate standards if applied
	vector<v4l2_standard> standard_list;
	v4l2_standard standard;
	v4l2_std_id current_standard;
	CLEAR(standard);
	standard.index = 0;
	if(-1 != xioctl(video_device, VIDIOC_G_STD, &current_standard))
	{
        while(0 == xioctl(video_device, VIDIOC_ENUMSTD, &standard))
        {
            if(standard.id & input_list[current_input].std)
            {
                standard_list.push_back(standard);
                log_message(0, "AVConfig: Standard %s is supported by current input.", standard.name);
                log_message(0, "AVConfig: The framerate defined by this standard is: %d", standard.frameperiod.denominator/standard.frameperiod.numerator);
                if(standard.id == current_standard)
                    log_message(0, "AVConfig: Standard %s is currently selected on input.", standard.name);
            }
            standard.index++;
        }
        if(errno != EINVAL || standard.index == 0)
        {
            log_errno("AVConfig: VIDIOC_ENUMSTD");
            return false;
        }
	}

	//enumerate controls
	vector<v4l2_queryctrl> queryctrl_list;
	vector<v4l2_control> control_list;
	map<unsigned long, vector<v4l2_querymenu> > querymenu_list;
	v4l2_queryctrl queryctrl;
	v4l2_control control;
	CLEAR(queryctrl);
	CLEAR(control);
	log_message(0, "AVConfig: Quering standard controls");
	queryctrl.id = V4L2_CID_BASE;
	while(queryctrl.id < V4L2_CID_LASTP1)
	{
	    queryctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
	    control.id    = queryctrl.id;
	    int res = query_control(video_device, &queryctrl, &control,
	                            queryctrl_list, control_list, querymenu_list);
        if(-1 == res)
        {
            log_errno("AVConfig: unable to query device control");
            return false;
        }
        else if(0 == res) break;
	}
	log_message(0, "AVConfig: Quering driver specific controls");
	queryctrl.id = V4L2_CID_PRIVATE_BASE;
    while(true)
    {
        queryctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
        control.id    = queryctrl.id;
        int res = query_control(video_device, &queryctrl, &control,
                                queryctrl_list, control_list, querymenu_list);
        if(-1 == res)
        {
            log_errno("AVConfig: unable to query device control");
            return false;
        }
        else if(0 == res) break;
    }

	//close the device
	close(video_device);

	//construct inputs setting
	Setting *video = getVideoSettings();

	try{ video->remove("input"); } catch(...){}
	video->add("input", Setting::TypeInt) = current_input;

	try{ video->remove("inputs"); } catch(...){}
	Setting &inputs = video->add("inputs", Setting::TypeGroup);
	for(int i = 0; i < input_list.size(); i++)
		inputs.add(fix_str(input_list[i].name), Setting::TypeInt) = i;

    //construct standarts setting
	try{ video->remove("standard"); } catch(...){}
	try{ video->remove("standards"); } catch(...){}
	if(!standard_list.empty())
	{
	    video->add("standard", Setting::TypeInt64) = (long long)current_standard;
        Setting &standards = video->add("standards", Setting::TypeGroup);
        for(int i = 0; i < standard_list.size(); i++)
            standards.add(fix_str(standard_list[i].name), Setting::TypeInt64) = (long long)standard_list[i].id;
	}

	//construct controls setting
	try{ video->remove("controls"); } catch(...){}
	Setting &controls = video->add("controls", Setting::TypeGroup);

	for(int i = 0; i < queryctrl_list.size(); i++)
	{
		Setting &control = controls.add(fix_str(queryctrl_list[i].name), Setting::TypeGroup);
		control.add("id", Setting::TypeInt) = (int)queryctrl_list[i].id;
		control.add("value", Setting::TypeInt) = (int)control_list[i].value;
		control.add("default_value", Setting::TypeInt) = (int)queryctrl_list[i].default_value;
		if(queryctrl_list[i].type == V4L2_CTRL_TYPE_MENU)
		{
			vector<v4l2_querymenu> items = querymenu_list[(int)queryctrl_list[i].id];
			for(int j = 0; j < items.size(); j++)
				control.add(fix_str(items[j].name), Setting::TypeInt64) = (long long)items[j].index;
		}
		else
		{
			control.add("minimum", Setting::TypeInt) = (int)queryctrl_list[i].minimum;
			control.add("maximum", Setting::TypeInt) = (int)queryctrl_list[i].maximum;
			control.add("step", Setting::TypeInt) = (int)queryctrl_list[i].step;
		}
	}

	return true;
}
Exemple #4
0
    void _apply(Setting& root, Setting& source, LockList* lockList)
    {
        Setting* s = nullptr;

        if (!source.isRoot()) {
            const char* name = source.getName();
            if (name != nullptr) {
                if (root.exists(name)) {
                    s = &root[name];

                    if (_isLocked(*s, true, lockList)) {
                        LogWarn("Ignored updating configuration '%s' to value "
                                "'%s'. Setting locked to value '%s'.",
                                s->getPath().c_str(),
                                settingToString(source).c_str(),
                                settingToString(*s).c_str());

                        return;
                    }

                    if (!s->isGroup()) {
                        root.remove(s->getIndex());
                        s = &root.add(name, source.getType());
                    }
                } else {
                    s = &root.add(name, source.getType());

                    if (_isLocked(*s, false, lockList)) {
                        LogWarn("Ignored creating configuration '%s' with "
                                "value '%s'. Setting locked.",
                                s->getPath().c_str(),
                                settingToString(*s).c_str());

                        root.remove(s->getIndex());
                        return;
                    }
                }
            } else {
                // List or array elements
                s = &root.add(source.getType());
            }
        } else {
            s = &root;
        }

        switch (source.getType())
        {
            case Setting::Type::TypeInt: {
                *s = (int)source;
                break;
            }

            case Setting::Type::TypeInt64: {
                *s = (long long)source;
                break;
            }

            case Setting::Type::TypeString: {
                *s = (const char*)source;
                break;
            }

            case Setting::Type::TypeBoolean: {
                *s = (bool)source;
                break;
            }

            case Setting::Type::TypeArray:
            case Setting::Type::TypeList:
            case Setting::Type::TypeGroup: {
                for (int i = 0; i < source.getLength(); ++i) {
                    _apply(*s, source[i], lockList);
                }
                break;
            }

            default: {
                assert(false);
                break;
            }
        }
    }