欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

C程序?qū)崿F(xiàn)監(jiān)聽長按物理power鍵3秒關(guān)機功能

要實現(xiàn)的功能:在android Framework層被裁剪掉的情況下,實現(xiàn)監(jiān)聽長按的物理power按鍵,實現(xiàn)長按3秒后關(guān)機功能;

從事成都二樞服務(wù)器租用托管,服務(wù)器租用,云主機,網(wǎng)站空間,域名申請,CDN,網(wǎng)絡(luò)代維等服務(wù)。

思路:使用event epoll,非阻塞式IO操作,同時避免無差別輪詢,做到避免忙輪和無差別輪詢提高效率;

要用到的epoll函數(shù):

epoll_create(EPOLL_SIZE_HINT);
epoll_wait(mEpollFd, mPendingEventItems, 8, -1);
epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, &eventItem)
epoll_ctl(mEpollFd, EPOLL_CTL_DEL, fd, &eventItem);

下面是實現(xiàn)的過程:

int main(int argc, char *argv[])
{
    ALOGI("robot test robot power");
	struct itimerval old_value;
	int tap_power_time = 0;
	int tap_power_type = 0;
	int tap_power_code = 0;
	int tap_power_value = 0;
    struct itimerval tick;
	int mEpollFd;
	const int EPOLL_SIZE_HINT = 8;
	const char* DEV_INPUT = "/dev/input/event1";
	struct epoll_event mPendingEventItems[8];
	
	unsigned char buf[1024] = {0};
	struct inotify_event *event = NULL;
	struct RawEvent* readBuffer = (struct RawEvent*) malloc (sizeof(struct RawEvent));
	mEpollFd = epoll_create(EPOLL_SIZE_HINT);
	int fd = open(DEV_INPUT, O_RDWR | O_CLOEXEC);

	/*
	* struct epoll_event {  
	*	uint32_t events;     // epoll events (bit mask)
	*	epoll_data_t data;   // User data  
	* };  
	*/
	struct epoll_event eventItem;
    memset(&eventItem, 0, sizeof(eventItem));
	/**
	* EPOLLIN: has data to read
	* EPOLLOUT: has data to write
	*/
    eventItem.events = EPOLLIN;

	/**
	* EPOLL_CTL_ADD: add fd to watching list
	* EPOLL_CTL_DEL: remove fd from watching list
	*/
	if (epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, &eventItem) == -1)
	{
		exit(0);
	}

	for (;;)
	{
		/**
		* parameter -1 : wait until event occur ;
		*            0 : return immediately when deal with a non-block event
		*/
		epoll_wait(mEpollFd, mPendingEventItems, 8, -1);
		int32_t readSize = read(fd, readBuffer, sizeof(struct input_event));
		struct input_event *event =(struct input_event*) readBuffer;

		tap_power_time = (int) event->time.tv_sec;
		tap_power_type = event->type;
		tap_power_code = event->code;
		tap_power_value = event->value;


		if(is_power_down_key(tap_power_type, tap_power_code, tap_power_value))
		{
			ALOGI("robot power down key");
			signal(SIGALRM,handle_exit);
			memset(&tick,0,sizeof(tick));
			tick.it_value.tv_sec= 3;
			tick.it_value.tv_usec= 0;
			setitimer(ITIMER_REAL,&tick,NULL);
		}
		else if(is_power_up_key(tap_power_type, tap_power_code, tap_power_value)) 
		{
			tick.it_value.tv_sec= 0;
			tick.it_value.tv_usec= 0;
			setitimer(ITIMER_REAL,&tick,NULL);
		}
		
	}

	epoll_ctl(mEpollFd, EPOLL_CTL_DEL, fd, &eventItem);
    return 0;
}
struct RawEvent {
    int32_t when;
    int32_t deviceId;
    int32_t type;
    int32_t code;
    int32_t value;
};

void handle_exit(int sig)
{
	ALOGI("robot 3 second time out ,now shutdown!");
	system("reboot -p");
}
int is_power_down_key(int type, int code, int value)
{
	int is_down = 0;
	is_down = (type == 1) && (code == 116) && (value == 1);
	return is_down;
}

int is_power_up_key(int type, int code, int value)
{
	int is_up = 0;
	is_up = (type == 1) && (code == 116) && (value == 0);
	return is_up;
}

網(wǎng)頁標(biāo)題:C程序?qū)崿F(xiàn)監(jiān)聽長按物理power鍵3秒關(guān)機功能
URL標(biāo)題:http://aaarwkj.com/article2/pcococ.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計、自適應(yīng)網(wǎng)站做網(wǎng)站、域名注冊網(wǎng)站制作、網(wǎng)站策劃

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)
av国语对白在线观看| 一区二区在线观看激情| 溪乱毛片一区二区三区| 免费观看国内性生活大片| 午夜91激情福利视频| 国产激情视频一区二区三区| 日本五十路亲子在线一区| 成人黄片在线免费播放| 最新欧美精品一区二区| 十八女毛片一区二区三区| 91国内外精品自在线播放| 97视频在线中文字幕| 欧美亚洲另类日韩综合网| 欧美欧美欧美欧美在线| 中文字幕一区二区中文字幕| 国产精品第一区第二区| 国产国产成人精品久久蜜| 日本人妻在线不卡视频| 91午夜福利国产精品| 五月婷婷色综合激情五月| 日韩国产传媒在线精品| 国产不卡视频观看网站| 日本 一区二区在线| 日本岛国大片在线视频| 国内揄拍国内精品对久久| 国产精品专区日产一区| 少妇互射视频免费视频| 亚洲精品午夜福利网| 中文字幕久久av一区二区| 欧美黄片一区二区三区三| 亚洲天堂成人av蜜臀| 日本道欧美一区二区aaaa| 国产一区二区黄色网页| 人妻少妇亚洲精品视频| 国产精品自拍午夜福利| 日本精品在线小视频| 国产成人综合久久二区| 亚洲性感美女男人的天堂| 亚洲日本韩国福利久久| 欧美一区二区精品网站| 四虎在线永久观看视频|