CHRE: /vendor/bin/chre

从上文知道IContexthub service最终通过socket和chre通信,暂且不关注chre通过 fastrpc和dsp的通信。

system/chre/host/msm/Android.mk

LOCAL_MODULE := chre
LOCAL_VENDOR_MODULE := true
LOCAL_CPP_EXTENSION := .cc
FASTRPC_INC := $(TARGET_OUT_INTERMEDIATES)/include/fastrpc/inc
LOCAL_ADDITIONAL_DEPENDENCIES ::= $(FASTRPC_INC)
LOCAL_SRC_FILES := \
    ../../platform/shared/host_protocol_common.cc \
    ../common/host_protocol_host.cc \
    ../common/socket_server.cc \
    daemon/chre_daemon.cc \
    daemon/generated/chre_slpi_stub.c
LOCAL_C_INCLUDES := \
    $(FASTRPC_INC) \
    system/chre/platform/slpi/include \
LOCAL_HEADER_LIBRARIES := chre_flatbuffers
LOCAL_SHARED_LIBRARIES := \
    libbase \
    libutils \
    libcutils \
    liblog \
LOCAL_SHARED_LIBRARIES += libadsprpc

# ps -A | grep chre


system        2050     1   19300   4888 do_sys_poll         0 S chre

ps -A | grep context


system       18927     1 2126252   5104 binder_ioctl_write_read 0 S [email protected]

 

kill contexthu-service场景

CHRE server收到断开信息

chre/host/common/socket_server.cc -> handleClientData -> LOGI("Client %" PRIu16 " disconnected", clientId)

CHRE    : Client 3 disconnected

[email protected]自动启动(init.rc不是one-shot), 再次注册service

ALOGI("Registration complete for %s/%s.",Interface::descriptor, name.c_str()); 


[email protected]: Registration complete for [email protected]::IContexthub/default.

重新和chre建立socket连接

SocketClient::reconnect() -> LOGD("Successfully (re)connected")
CHRE    : Successfully (re)connected

SocketServer::acceptClientConnection()

03-27 15:18:27.290 18996 18996 I CHRE    : Accepted new client connection (count 1), assigned client ID 1

 

kill chre

CHRE    : Caught signal 15
CHRE    : Exiting poll loop: Interrupted system call
CHRE    : Socket disconnected on remote end
ContextHubHal: Lost connection to CHRE daemon

CHRE    : Shutdown complete
/vendor/bin/chre: vendor/qcom/proprietary/commonsys-intf/adsprpc/src/fastrpc_apps_user.c:1006: remote_handle_open: Successfully opened handle 0x37260a70 for chre_slpi on domain 2
/vendor/bin/chre: vendor/qcom/proprietary/commonsys-intf/adsprpc/src/fastrpc_apps_user.c:1006: remote_handle_open: Successfully opened handle 0x372609f0 for chre_slpi on domain 2


CHRE    : CHRE on SLPI started
CHRE    : Ready to accept connections
CHRE    : Successfully (re)connected
ContextHubHal: Reconnected to CHRE daemon
CHRE    : Accepted new client connection (count 1), assigned client ID 1

main函数分析

CHRE: /vendor/bin/chre_第1张图片

分为3部分:

1. 在slpi侧建立thread运行chre处理来着host的 Events,

对events的处理分两步a. 放入队列 b.处理每个nanoApp上的event 

2. 处理来着chre的message

3. 通过socket:chre处理来着client的message, 调用slpi/chre处理

 

NanoApp是个什么

组成

nanoappStart/HandleEvent/End : entry points from the system into the nanoapp 也就是实现这3个函数,其中主要是HandleEvent

NanoApp的创建

实现entryPoints: start/end/handleEvent

DLL_EXPORT const struct chreNslNanoappInfo _chreNslDsoNanoappInfo = {
  .magic = CHRE_NSL_NANOAPP_INFO_MAGIC,
  .structMinorVersion = CHRE_NSL_NANOAPP_INFO_STRUCT_MINOR_VERSION,
  .targetApiVersion = CHRE_API_VERSION,

  // These values are supplied by the build environment
  .vendor = NANOAPP_VENDOR_STRING,
  .name = NANOAPP_NAME_STRING,
  .isSystemNanoapp = 0,
  .appId = NANOAPP_ID,
  .appVersion = NANOAPP_VERSION,

  .entryPoints = {
    .start = nanoappStart,
    .handleEvent = nanoappHandleEvent,
    .end = nanoappEnd,
  },
};

编译成什么

是个共享库 so文件

target_so = '${BUILDPATH}/'+LIBNAME+'.so'

BUILD_DLLS += chre_app_sensor_cfg

入口点的调用

start

当通过socket: chre收到loadNanoapp时,创建nanoApp, 调用start函数

handleEvent

当收到client发来的message时

CHRE: /vendor/bin/chre_第2张图片

你可能感兴趣的:(人工智能)