ril层的所有代码分析

ril/rild下的文件 rild.c->mian()为函数入口

 int main(int argc, char **argv)

//

....

//

OpenLib:
#endif
   switchUser();
//打开dlopen()加载vendor RIL 获取由RIL_register(funcs);注册进来的参数,并解析
    dlHandle = dlopen(rilLibPath, RTLD_NOW);

    if (dlHandle == NULL) {
        fprintf(stderr, "dlopen failed: %s\n", dlerror());
        exit(-1);
    }
//1:消息队列的入口1.到select阻塞//每当看到打印信息,不按顺序打下来说明阻塞
RIL_startEventLoop();
//通过dlsym函数得到rilInit函数指针的引用
    rilInit = (const RIL_RadioFunctions *(*)(const struct RIL_Env *, int, char **))dlsym(dlHandle, "RIL_Init");

    if (rilInit == NULL) {
        fprintf(stderr, "RIL_Init not defined or exported in %s\n", rilLibPath);
        exit(-1);
    }

    if (hasLibArgs) {
        rilArgv = argv + i - 1;
        argc = argc -i + 1;
    } else {
        static char * newArgv[MAX_LIB_ARGS];
        static char args[PROPERTY_VALUE_MAX];
        rilArgv = newArgv;
        property_get(LIB_ARGS_PROPERTY, args, "");
        argc = make_argv(args, rilArgv);
    }

    // Make sure there's a reasonable argv[0]
    rilArgv[0] = argv[0];
//2:利用得到的rilInit函数指针,调用真正的RIL_Init
    funcs = rilInit(&s_rilEnv, argc, rilArgv);

   

RIL_register(funcs);

done:

    while(1) {
        // sleep(UINT32_MAX) seems to return immediately on bionic
        sleep(0x00ffffff);
    }

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

RIL_startEventLoop()函数分析—ril/libril->ril.cpp

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

RIL_startEventLoop(void) {
    int ret;
    pthread_attr_t attr;
LOGD("-2--ril.cpp--RIL_startEventLoop---");
    /* spin up eventLoop thread and wait for it to get started */
    s_started = 0;
    pthread_mutex_lock(&s_startupMutex);

    pthread_attr_init (&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 LOGD("-1-ril.cpp--kai-kou--pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);------");
    ret = pthread_create(&s_tid_dispatch, &attr,eventLoop, NULL);//创建线程,为入口函数
 LOGD("-2.....-ril.cpp--tiao-chu--rpthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);----");
    while (s_started == 0) {
        pthread_cond_wait(&s_startupCond, &s_startupMutex);
    }

    pthread_mutex_unlock(&s_startupMutex);

    if (ret < 0) {
        LOGE("Failed to create dispatch thread errno:%d", errno);
        return;
    }
}

------

eventLoop(void *param) {

 1.---ril_event_init();//初始化

void ril_event_init()
{
    MUTEX_INIT();
LOGD("-2.2-Ril_evnet.cpp-ril_event_init-shi-xian-han-shu-");
    FD_ZERO(&readFds);
    init_list(&timer_list);
    init_list(&pending_list);
    memset(watch_table, 0, sizeof(watch_table));
}


2.--- ret = pipe(filedes);

 

3.---ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,processWakeupCallback, NULL); 在ril/libril/ril_event.cpp实现

void ril_event_set(struct ril_event * ev, int fd, bool persist, ril_event_cb func, void * param)
{
LOGD("----RIL_evnent.cpp-shi-xian--void ril_event_set(struct ril_event * ev, int fd, bool persist, ril_event_cb func, void * param)-");
    dlog("~~~~ ril_event_set %x ~~~~", (unsigned int)ev);
    memset(ev, 0, sizeof(struct ril_event));
    ev->fd = fd;
    ev->index = -1;
    ev->persist = persist;
    ev->func = func;
    ev->param = param;
    fcntl(fd, F_SETFL, O_NONBLOCK);
}

3.1processWakeupCallback

static void processWakeupCallback(int fd, short flags, void *param) {
    char buff[16];
    int ret;
LOGD("--2.5-ril_event_set--processWakeupCallback- read(s_fdWakeupRead, &buff, sizeof(buff));---");
    LOGV("processWakeupCallback");

    /* empty our wakeup socket out */
    do {
        ret = read(s_fdWakeupRead, &buff, sizeof(buff));
    } while (ret > 0 || (ret < 0 && errno == EINTR));
}

4.---rilEventAddWakeup (&s_wakeupfd_event);

static void rilEventAddWakeup(struct ril_event *ev) {
 LOGD("-2.7-rilEventAddWakeup--write--tiao--ru--  ril_event_add(ev);---");
    ril_event_add(ev);
 LOGD("--2.8--ril_event_add(ev);---tiao--chu---");
    triggerEvLoop();
}

4.1---void ril_event_add(struct ril_event * ev)   在ril/libril/ril_event.cpp实现
{
LOGD("---RIL_evnent.cpp--shi--xian--void ril_event_add(struct ril_event * ev)----");
    dlog("~~~~ +ril_event_add ~~~~");
    MUTEX_ACQUIRE();
    for (int i = 0; i < MAX_FD_EVLL) {
 //1:
            watch_table[i] = ev;//把上面ril_event_add函数添加的事件_wakeupfd_event结构体添加到这个数组来
            ev->index = i;
            dlog("~~~~ added at %d ~~~~", i);
            dump_event(ev);
 //2:
            FD_SET(ev->fd, &readFds);
            if (ev->fd >= nfds) nfds = ev->fd+1;
            dlog("~~~~ nfds = %d ~~~~", nfds);
            break;ENTS; i++) {
        if (watch_table[i] == NU
        }
    }
    MUTEX_RELEASE();
    dlog("~~~~ -ril_event_add ~~~~");
}
4.2---static void triggerEvLoop() {
    int ret;
 LOGD("--- ret = write (s_fdWakeupWrite, " ", 1);---");
    if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
        /* trigger event loop to wakeup. No reason to do this,
         * if we're in the event loop thread */
         do {
            ret = write (s_fdWakeupWrite, " ", 1);
         } while (ret < 0 && errno == EINTR);
    }
}

5.ril_event_loop();

 

 

 

}

 

你可能感兴趣的:(ril层的所有代码分析)