(2)RIL简析(高通)——消息处理

  • RIL如何启动及初始化?
  • RILJ的消息如何传递和被处理?

    • event table的定义
    • requested event的处理函数
    • ril_event的管理
    • RIL_REQEUST执行结果的返回
    • RIL_UNSOL类型消息的上报
  • 一个消息处理的具体例子——SETUP_DATA_CALL

  • 如何添加一个RIL消息和对应的处理函数?

event table的定义

RIL所有的EVENT都定义在Ril.h中,有以RIL_REQUEST和RIL_UNSOL_RESPONSE开头的消息,前者代表主动请求,后者一般是上报的消息,例如下面这2个:

#define RIL_REQUEST_SETUP_DATA_CALL 27
#define RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED 1000

当然,无论是REQUEST还是UNSOL_RESPONSE都会带参数,因此还需定义消息对应的结构体,例如RADIO_STATE的结构体:

typedef enum {
    RADIO_STATE_OFF = 0,                   /* Radio explictly powered off (eg CFUN=0) */
    RADIO_STATE_UNAVAILABLE = 1,           /* Radio unavailable (eg, resetting or not booted) */
    /* States 2-9 below are deprecated. Just leaving them here for backward compatibility. */
    RADIO_STATE_SIM_NOT_READY = 2,         /* Radio is on, but the SIM interface is not ready */
    RADIO_STATE_SIM_LOCKED_OR_ABSENT = 3,  /* SIM PIN locked, PUK required, network
                                              personalization locked, or SIM absent */
    RADIO_STATE_SIM_READY = 4,             /* Radio is on and SIM interface is available */
    RADIO_STATE_RUIM_NOT_READY = 5,        /* Radio is on, but the RUIM interface is not ready */
    RADIO_STATE_RUIM_READY = 6,            /* Radio is on and the RUIM interface is available */
    RADIO_STATE_RUIM_LOCKED_OR_ABSENT = 7, /* RUIM PIN locked, PUK required, network
                                              personalization locked, or RUIM absent */
    RADIO_STATE_NV_NOT_READY = 8,          /* Radio is on, but the NV interface is not available */
    RADIO_STATE_NV_READY = 9,              /* Radio is on and the NV interface is available */
    RADIO_STATE_ON = 10                    /* Radio is on */
} RIL_RadioState;

通过搜索,发现ril_commands.h中还有定义RIL_REQUEST的数组元素,字面意思来看,明显是消息处理入口和返回的函数入口:
{RIL_REQUEST_SETUP_DATA_CALL, dispatchDataCall, responseSetupDataCall}

ril.cpp居然直接引入了这些定义,所有消息和对应的函数都存在s_commands数组里了:

ril.cpp
typedef struct {
   int requestNumber;
   void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
   int (*responseFunction) (Parcel &p, void *response, size_t responselen);
} CommandInfo;

static CommandInfo s_commands[] = {
#include "ril_commands.h"
};

那么,这些消息对应的函数是怎样被匹配并对应执行的呢?下一节。


requested event的处理

我们要看消息是如何被处理的,先从消息的监听入手,就应该能找到对应的处理函数了。
既然这些消息是上层下发的,那么RIL就是通过socket来接收到消息。先回顾下socket监听是怎样建立的,应该就能找到消息处理的入口。
上一篇有讲到,RIL_register有监听RILD socket的代码:

ril.cpp::RIL_register

    /* Initialize socket1 parameters */
    s_ril_param_socket = {
                        RIL_SOCKET_1,             /* socket_id */
                        -1,                       /* fdListen */
                        -1,                       /* fdCommand */
                        PHONE_PROCESS,            /* processName */
                        &s_commands_event,        
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值