Ejemplo n.º 1
0
    FILE* __mlibc_filelist_get(void *p, int n)
    {
        HList<FILE*>* list;

        if( p == NULL ) p = __mlibc_filelist_initializer(p);
        list = (HList<FILE*>*)p;
        if( list->size() <= n ) return NULL;
        return list->get(n);
    }
Ejemplo n.º 2
0
/** メインスレッド */
void ImeServer::service()
{
    uintptr_t targetID = MonAPI::Message::lookupMainThread("MONITOR.BIN");
    if (targetID == THREAD_UNKNOWN) {
        printf("IME: Monitor server not found\n");
        exit(1);
    }

    if (MonAPI::Message::send(targetID, MSG_STARTED, 0, 0, 0, NULL)) {
        printf("IME: Server start failed\n");
        exit(1);
    }

    // 辞書が読めなかったときはかな漢字変換はすべて失敗を返す
    bool dicLoaded = loadDictionary();

    MessageInfo info;
    while (1) {
        if (!MonAPI::Message::receive(&info)) {
            switch(info.header) {
            case MSG_IMESERVER_GETKANJI:
                {
                    HList<MonAPI::CString> result;
                    int hit = getKanji(info.str, &result);

                    // MSG_IMESERVER_GETKANJI
                    // arg2: ヒット数
                    if (dicLoaded == true) {
                        MonAPI::Message::reply(&info, hit, 0, NULL);
                    } else {
                        MonAPI::Message::reply(&info, 0, 0, NULL);
                    }

                    if (dicLoaded == true && hit > 0) {
                        // MSG_IMESERVER_STARTKANJI
                        // arg1: ヒット数
                        MonAPI::Message::sendReceive(&info, info.from, MSG_IMESERVER_STARTKANJI, hit, 0, 0, NULL);

                        for (int i = 0; i < hit; i++) {
                            // MSG_IMESERVER_KANJI
                            // arg1: ヒット数
                            // arg2: カウンタ
                            // str : よみ→漢字
                            MonAPI::Message::sendReceive(&info, info.from, MSG_IMESERVER_KANJI, hit, i, 0, (const char*)result.get(i));
                            //printf("%d: %s\n", i, (const char*)result.get(i));
                        }

                        // MSG_IMESERVER_ENDKANJI
                        // arg1: ヒット数
                        MonAPI::Message::sendReceive(&info, info.from, MSG_IMESERVER_ENDKANJI, hit, 0, 0, NULL);
                    }
                }
                break;
            case MSG_IMESERVER_GETYOMI:
                {
                    // MSG_IMESERVER_GETYOMI
                    // arg2: 0-失敗 1-成功
                    // str : 漢字→よみ
                    char result[MAX_TEXT_LEN];
                    if (dicLoaded == true && getYomi(info.str, result) == true) {
                        strncpy(info.str, result, MAX_TEXT_LEN);
                        MonAPI::Message::reply(&info, 1, 0, result);
                    } else {
                        strncpy(info.str, "", MAX_TEXT_LEN);
                        MonAPI::Message::reply(&info, 0, 0, "");
                    }
                }
                break;
            case MSG_IMESERVER_GETKANA:
                {
                    // MSG_IMESERVER_GETKANA
                    // arg2: 0-失敗 1-成功
                    // str : 入力文字→かな
                    char result[MAX_TEXT_LEN];
                    if (getKana(info.str, result) == true) {
                        strncpy(info.str, result, MAX_TEXT_LEN);
                        MonAPI::Message::reply(&info, 1, 0, result);
                    } else {
                        strncpy(info.str, "", MAX_TEXT_LEN);
                        MonAPI::Message::reply(&info, 0, 0, "");
                    }
                }
                break;
            case MSG_IMESERVER_GETROMAN:
                {
                    // MSG_IMESERVER_GETROMAN
                    // arg2: 0-失敗 1-成功
                    // str : かな→入力文字
                    char result[MAX_TEXT_LEN];
                    if (getRoman(info.str, result) == true) {
                        strncpy(info.str, result, MAX_TEXT_LEN);
                        MonAPI::Message::reply(&info, 1, 0, result);
                    } else {
                        strncpy(info.str, "", MAX_TEXT_LEN);
                        MonAPI::Message::reply(&info, 0, 0, "");
                    }
                }
                break;
            }
        }
    }
}
Ejemplo n.º 3
0
void Monitor::CheckServers()
{
    //char buf[256];
    PsInfo info;
    for (int i = 0; i < servers.size(); i++)
    {
        alive[i] = false;
    }

    syscall_set_ps_dump();

    while (syscall_read_ps_dump(&info) == 0)
    {
        CString name = info.name;

        for (int i = 0; i < servers.size(); i++)
        {
            if (servers.get(i) == name)
            {
                alive[i] = true;
                continue;
            }
        }
    }

    for (int i = 0; i < servers.size(); i++)
    {
        if (alive[i]) continue;
        if (!firstLoad && servers[i] == "OLDSHELL.EX5") continue;
        // sorry we can not use printf before process server starts.
        syscall_print("loading ");
        syscall_print((const char*)paths.get(i));
        syscall_print("....");

        // We need OutStream
        MessageInfo msg;
        if (servers[i] == "SCHEME.EX5")
        {
            uint32_t tid;
            uint32_t targetID = Message::lookupMainThread("SCREEN.EX5");
            if (targetID == THREAD_UNKNOWN || Message::sendReceive(&msg, targetID, MSG_SCREEN_GET_STREAM_HANDLE)) {
                syscall_print("SCREEN.EX5 not found\n");
                continue;
            }
            syscall_print(monapi_call_process_execute_file_get_tid((const char*)paths.get(i), MONAPI_FALSE, &tid, msg.arg2, msg.arg2) == 0? "OK\n" : "NG\n");
        }
        else
        {
            syscall_print(monapi_call_process_execute_file((const char*)paths.get(i), MONAPI_FALSE) == 0? "OK\n" : "NG\n");
        }

        for (;;)
        {
            if (Message::receive(&msg)) continue;
            if (msg.header == MSG_STARTED) break;
        }

    }

    if (firstLoad) firstLoad = false;
}