dynamic generate command line parameters for qt embedded application

Read the fucking source code below.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <linux/input.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#define DIR_PATH    "/dev/input"
#define NODE_PREFIX    "event"
int main(int argc,char **argv)
{
    DIR *tdir;
    struct dirent *tdirent;
    struct input_event tevent;
    unsigned int evbit;
    int fd;
    unsigned char event_node_name[32];
    int node_prefix_len=strlen(NODE_PREFIX);
    int ret;
    int valid_cnt=0;
    int event_type;
    //check input parameters.
    if(argc<2)
    {
        printf("usage:%s <0/1>\n",argv[0]);
        printf("<0>: scan mouse event nodes\n");
        printf("<1>: scan keyboard event nodes\n");
        return -1;
    }
    if(!strncmp(argv[1],"0",1))
    {
        event_type=EV_REL;
    }else if(!strncmp(argv[1],"1",1))
    {
        event_type=EV_KEY;
    }else{
        printf("error:invalid scan type!\n");
        return -1;
    }
    tdir=opendir(DIR_PATH);
    if(!tdir)
    {
        printf("open dir failed!\n");
        return -1;
    }
    while((tdirent=readdir(tdir))!=NULL)
    {
        if(!strncmp(tdirent->d_name,NODE_PREFIX,node_prefix_len))
        {
            sprintf(event_node_name,"%s/%s",DIR_PATH,tdirent->d_name);
            //printf("%s,",event_node_name);
            fd=open(event_node_name,O_RDONLY);
            if(fd<0)
            {
                printf("open event node failed:%s\n",strerror(errno));
                continue;
            }
            ret=ioctl(fd,EVIOCGBIT(0,EV_MAX),&evbit);
            if(evbit&(0x1<<event_type))
            {
                printf("%s\n",event_node_name);
                valid_cnt++;
            }
            close(fd);
        }
    }
    closedir(tdir);
    return valid_cnt;
}

#!/bin/bash

#brief:to solve match correct event node when EAVCapture starts.
#date:September 17,2015.
#author:zhangshaoyan,shell.albert@gmail.com

#qt's start command line parameters.
mouseplug=
kbdplug=
allplug="-platform linuxfb"

#scan /dev/input directory to get valid event that supports EV_REL.
./evtest.bin 0 > mouse_event.log
mouse_event_cnt=$?

#scan /dev/input diretory to get valid event that supports EV_KEY.
./evtest.bin 1 > kbd_event.log
kbd_event_cnt=$?

#generate the final one-line start parameter.
if [ $mouse_event_cnt -gt 0 ];then
    while read line
    do
        mouseplug="$mouseplug -plugin evdevmouse:$line"
    done < mouse_event.log
fi

if [ $kbd_event_cnt -gt 0 ];then
    while read line
    do
        kbdplug="$kbdplug -plugin evdevkeyboard:$line"
    done < kbd_event.log
fi

allplug="$allplug $mouseplug $kbdplug"
echo $allplug


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值