From: Petr T. <pto...@ss...> - 2002-04-03 21:28:56
|
Caues, Zde je nejake priklad jak prozatim vidim generovani veci z IDL spojenych s RPC volanim. Spis nez abyste si to precetli a prostudovali, to posilam abychom v pondeli na schuzce nad tim mohli pokecat a ja to tam nemusel psat znova, proto tu nepisu duvody proc je to ci ono tak ci tak. Hlavne ale je dole videt jak by vypadalo uzivatelske programovani (planovani udalosti a rpc je to same). Petr predpoklady: -existuje property vector, ktera muze obsahovat property typu "Any" (ala CORBA::Any), kde jde skladovat jakoukoli jinou property :-) (mimojine to ma peknou vlastnost ze IDL pak nemusi vedet nic o typech argumentu funkci (asi)). // Trida Monster. class Monster : public Object { void function_a( arg1, arg2 ); void function_b( arg1, arg2 ); /* $IDL: RPC */ }; Vygeneruji se: class MonsterFactory; // Vlastni factory pro tridu Monster. class MonsterRpc; // Trida ktera vyvolava vzdalene funkce (je naplanovana // jako event u ciloveho objektu). class MonsterRpcFactory; // Factory k MonsterRpc. identifikace funkci: MONSTER_FUNCTION_B_ARG1TYPE_ARG2TYPE class MonsterRpc : public Object { static ObjectPointer<MonsterRpc> create_rpc_for_function_b( arg1, arg2 ) { MonsterRpcFactory * monster_rpc_factory = ...; ObjectPointer<MonsterRpc> rpc = monster_rpc_factory->create(); rpc->func_id = MONSTER_FUNCTION_B_ARG1TYPE_ARG2TYPE; rpc->arg_array.reserve( 2 ); rpc->arg_array.push_back( arg1 ); rpc->arg_array.push_back( arg2 ); return rpc; } static void function_b( ObjectPointer<Monster> monster, arg1, arg2 ) { send( monster, MonsterRpc::create_rpc_for_function_b( arg1, arg2 ), ASAP ); } virtual void execute( ObjectPointer<Object> o ) { ObjectPointer<Monster> m = o; switch( this->func_id ) { // Lze udelat nejak tabulkou? case MONSTER_FUNCTION_B_ARG1TYPE_ARG2TYPE: m->function_b( this->arg_array[0], this->arg_array[1] ); return; case ... // Zde bud switch na vsechny rpc funkce ve vsech // predcich tridy Monster, nebo MonsterRpc zdedit z RPC tridy predka. Pak: // default: // Super::execute( o ); // Udela vlastni switch. // return; } }; Co lze provadet: 1/ Prime volani metody na lokalnim objektu. monster->function_a( arg1, arg2 ); monster->function_b( arg1, arg2 ); 2/ RPC zavolani metody objektu. MonsterRpc::function_b( monster, arg1, arg2 ); // staticka metoda 3/ Naplanovani udalosti objektu. PEventHandle handle; handle = send( monster, event_object, time ); // Posle objekt "event_object" objektu "monster" // a naplanuje jeho vyvolani na cas "time". // Lze vyvolat "opozdene RPC" rucne na vlastni cas: handle = send( monster, MonsterRpc::create_rpc_for_function_b( arg1, arg2 ), time ); Poznamky nakonec: - jak presne se bude chovat "handle.kill()"? |