Lesson7 Callback on Events

module {   interface IFoo { Foo; }

interface IBar { Bar; }

class CFooBar inherit CApplet { interface IFooBar { Foo; }

interface IBar; callbacks { // same as JFooBarEvents FooAlarm; }   } }


 * 1) include "FooBarDemo.h"
 * 2) include 

using namespace Elastos; using namespace Elastos.Vanilla;

ECode OnFooAlarm(PVoid userData, PInterface pSender) {   CConsole::WriteLine("====== CALLing OnFooAlarm ======"); CFooBar::RemoveFooAlarmCallback(pSender, OnFooAlarm, NULL); CApplet::RequestToQuit(pSender, 0); return NOERROR; }

ECode CFooBar::OnFooAlarm(PVoid userData, PInterface pSender) {   CConsole::WriteLine("====== CALLing OnFooAlarm ======"); CFooBar::RemoveFooAlarmCallback(pSender, OnFooAlarm, NULL); Callback::RequestToQuit(0); // CApplet::RequestToQuit(pSender, 0); return NOERROR; }

ECode CFooBar::Main(const BufferOf& args) {   IBar* pBar; ECode ec = CFooBar::New(&pBar); if (FAILED(ec)) { return ec; }   pBar->Bar;

ec = CFooBar::AddFooAlarmCallback(pBar, OnFooAlarm, NULL); if (FAILED(ec)) { pBar->Release; return ec; }

IFoo* pFoo; pFoo = IFoo::Probe(pBar); if (pFoo) { pFoo->Foo; }

// CApplet::DeleteObjectAtQuit(pFoo); return NOERROR; }

ECode CFooBar::Quit(Int32 n) { m_pFoo->Release; return NOERROR; }