常用C++代码技巧

1、 property_get/property_set
   每个属性都有一个名称,他们都是字符串格式。属性被大量使用在Android系统中,用来记录系统设置或进程之间的信息交换。属性是在整个系统中全局可见的。每个进程可以get/set属性。
在系统初始化时,Android将分配一个共享内存区来存储的属性。这些是由“init”守护进程完成的,其源代码位于:device/system/init。“init”守护进程将启动一个属**。
属在“init”守护进程中运行。每一个客户端想要设置属性时,必须连接属

,再向其发送信息。属**将会在共享内存区中修改和创建属性。任何客户端想获得属性信息,可以从共享内存直接读取。这提高了读取性能。 客户端应用程序可以调用libcutils中的API函数以GET/SET属性信息。libcutils的源代码位于:device/libs/cutils。API函数是:

int property_get(const char *key, char *value, const char *default_value);

int property_get(const char *key, const char *value);

实例1:参数分离

#include <log/log.h>
#include <cutils/properties.h>
#include <cstdio>
#include <cstdlib>
#include <string.h>
static strSyncAEInitInfo gSyncAEInitInfo_1111 =static strSyncAEInitInfo gSyncAEInitInfo_2222 =const strSyncAEInitInfo*
getSyncAEInitInfo()
{
    
    
	char pSensorName[PROPERTY_VALUE_MAX];
	property_get("persist.vendor.camera.sensor0", pSensorName, "NULL");
	ALOGD("Sensor Name xxxxxxxxxxxxxxx=%s", pSensorName);
	if(0 != strstr(pSensorName,"xxxx1111_mipi_raw"))
	{
    
    
	    ALOGD("Sensor Name1 xxxxxxxxxxxxxxx=%s", pSensorName);
		return &gSyncAEInitInfo_1111;
	}
	else if(0 != strstr(pSensorName,"xxxx2222_mipi_raw"))
	{
    
    
	    ALOGD("Sensor Name2 xxxxxxxxxxxxxxx=%s", pSensorName);
		return &gSyncAEInitInfo_2222;
	}
	ALOGD("Sensor Name3 xxxxxxxxxxxxxxx=%s", pSensorName);
	return &gSyncAEInitInfo;
}

疑问1:persist.vendor.camera.sensor0 在哪获取的?

mtkcam/drv/src/sensor/common/v1/HalSensorList.cpp
中 这块是厂商自己定制,具体在哪,要看具体代码

     searchsensor
     property_set("persist.vendor.camera.sensor.number", SensorNum);
     到此就有set 和 get 的操作

猜你喜欢

转载自blog.csdn.net/weixin_38328785/article/details/115342811
今日推荐