Ril分析四——来自网络端事件流程
从modem传递来的网络端事件,通过readLoop线程处理:
readLoop读取数据过程:
static void *readerLoop(void *arg)
{
for (;;) {
//从与modem通信设备端口读取数据
line = readline();
if (line == NULL) {
break;
}
//处理数据
processLine(line);
}
onReaderClosed();
return NULL;
}
static void processLine(const char *line)
{
if (sp_response == NULL) {
//来自网络端事件
handleUnsolicited(line);
} else if (isFinalResponseSuccess(line)) {
//客户端请求处理返回
sp_response->success = 1;
handleFinalResponse(line);
}
}
网络端事件处理过程:
static void handleUnsolicited(const char *line)
{
//onUnsolicited
if (s_unsolHandler != NULL) {
s_unsolHandler(line, NULL);
}
}
static void onUnsolicited (const char *s, const char *sms_pdu)
{
//初始化传入的ril.cpp中RIL_onUnsolicitedResponse函数
RIL_onUnsolicitedResponse (
RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED,
NULL, 0);
}
Void RIL_onUnsolicitedSendResponse(int unsolResponse, void *data,
size_t datalen, int client_id)
{
unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
Parcel p;
p.writeInt32 (RESPONSE_UNSOLICITED);
p.writeInt32 (unsolResponse);
//调用ril中网络端请求的响应函数
ret = s_unsolResponses[unsolResponseIndex]
.responseFunction(p, data, datalen);
//将数据传递给响应的设备
ret = sendResponse(p, client_id);
return;
}
同样以数组映射表形式存储网络端事件响应请求接口:
typedef struct {
int requestNumber;
int (*responseFunction) (Parcel &p, void *response,
size_t responselen);
WakeType wakeType;
} UnsolResponseInfo;
static UnsolResponseInfo s_unsolResponses[] = {
#include "ril_unsol_commands.h"
};
ril_unsol_commands.h:
{RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, responseVoid, WAKE_PARTIAL},
{RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, responseVoid, WAKE_PARTIAL},
{RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, responseVoid, WAKE_PARTIAL},
{RIL_UNSOL_RESPONSE_NEW_SMS, responseString, WAKE_PARTIAL},
……