void Stoppable::prepareRecursive () { for (Children::const_iterator iter (m_children.cbegin ()); iter != m_children.cend(); ++iter) iter->stoppable->prepareRecursive (); onPrepare (); }
void SimplePlayer::onMessageReceived(const sp<AMessage> &msg) { switch (msg->what()) { case kWhatSetDataSource: { status_t err; if (mState != UNINITIALIZED) { err = INVALID_OPERATION; } else { CHECK(msg->findString("path", &mPath)); mState = UNPREPARED; } uint32_t replyID; CHECK(msg->senderAwaitsResponse(&replyID)); sp<AMessage> response = new AMessage; response->setInt32("err", err); response->postReply(replyID); break; } case kWhatSetSurface: { status_t err; if (mState != UNPREPARED) { err = INVALID_OPERATION; } else { sp<RefBase> obj; CHECK(msg->findObject("native-window", &obj)); mNativeWindow = static_cast<NativeWindowWrapper *>(obj.get()); err = OK; } uint32_t replyID; CHECK(msg->senderAwaitsResponse(&replyID)); sp<AMessage> response = new AMessage; response->setInt32("err", err); response->postReply(replyID); break; } case kWhatPrepare: { status_t err; if (mState != UNPREPARED) { err = INVALID_OPERATION; } else { err = onPrepare(); if (err == OK) { mState = STOPPED; } } uint32_t replyID; CHECK(msg->senderAwaitsResponse(&replyID)); sp<AMessage> response = new AMessage; response->setInt32("err", err); response->postReply(replyID); break; } case kWhatStart: { status_t err = OK; if (mState == UNPREPARED) { err = onPrepare(); if (err == OK) { mState = STOPPED; } } if (err == OK) { if (mState != STOPPED) { err = INVALID_OPERATION; } else { err = onStart(); if (err == OK) { mState = STARTED; } } } uint32_t replyID; CHECK(msg->senderAwaitsResponse(&replyID)); sp<AMessage> response = new AMessage; response->setInt32("err", err); response->postReply(replyID); break; } case kWhatStop: { status_t err; if (mState != STARTED) { err = INVALID_OPERATION; } else { err = onStop(); if (err == OK) { mState = STOPPED; } } uint32_t replyID; CHECK(msg->senderAwaitsResponse(&replyID)); sp<AMessage> response = new AMessage; response->setInt32("err", err); response->postReply(replyID); break; } case kWhatReset: { status_t err = OK; if (mState == STARTED) { CHECK_EQ(onStop(), (status_t)OK); mState = STOPPED; } if (mState == STOPPED) { err = onReset(); mState = UNINITIALIZED; } uint32_t replyID; CHECK(msg->senderAwaitsResponse(&replyID)); sp<AMessage> response = new AMessage; response->setInt32("err", err); response->postReply(replyID); break; } case kWhatDoMoreStuff: { int32_t generation; CHECK(msg->findInt32("generation", &generation)); if (generation != mDoMoreStuffGeneration) { break; } status_t err = onDoMoreStuff(); if (err == OK) { msg->post(10000ll); } break; } default: TRESPASS(); } }
void MenuMaker::input(int key) { if (currentMenu->entries->size()==0 && ! (key == MENUMAKER_INPUT_LEFT || key == MENUMAKER_INPUT_BACK)) return; switch(key) { case MENUMAKER_INPUT_UP: if (currentEntry <= 0) currentEntry = currentMenu->entries->size()-1; // TODO else if (rollover) else currentEntry--; break; case MENUMAKER_INPUT_DOWN: if (currentEntry >= currentMenu->entries->size()-1) currentEntry = 0; else currentEntry++; break; case MENUMAKER_INPUT_LEFT: // TODO // if in widget: // decrease() // else if in menu input(MENUMAKER_INPUT_BACK); return; case MENUMAKER_INPUT_RIGHT: // TODO // if in widget: // increase() // else if in menu input(MENUMAKER_INPUT_SELECT); return; case MENUMAKER_INPUT_BACK: { if (history->size() <= 0) return; MenuMakerMenu* b = history->pop(); MenuMakerMenu* oldMenu = currentMenu; const int oid = currentMenu->id; int from = 0; const int n = b->entries->size(); for (int i=0;i<n;i++) { if (b->entries->get(i)->id == oid) { from = i; break; } } onLeave(oldMenu); currentEntry = from; currentMenu = b; redraw(); onExit(oldMenu); return; // return, no break. this is select/back not navigation within the current list; } case MENUMAKER_INPUT_SELECT: { MenuMakerEntry* e = currentMenu->entries->get(currentEntry); MenuMakerMenu* m; switch(e->type) { // Jaguar case MENUMAKER_TYPE_SUBMENU: m = resolveMenu(e->id); onPrepare(m); select(m); break; case MENUMAKER_TYPE_SELECT_SINGLE: { int old = *((int*)currentMenu->choice); *((int*)currentMenu->choice) = e->id; onSelection(currentMenu, &old); break; } case MENUMAKER_TYPE_SELECT_MULTI: { bool old[currentMenu->entries->size()]; memcpy(old, currentMenu->choice, sizeof(bool) * currentMenu->entries->size()); ((bool*)currentMenu->choice)[currentEntry] = !((bool*)currentMenu->choice)[currentEntry]; onSelection(currentMenu, old); } break; default: onEntry(e->id); break; } return; // return, no break. this is select/back not navigation within the current list } default: return; } highlight(currentEntry); }