Posted by: smallonely | December 3, 2003

[CORBA] POA 介面 – (2) the POA mapping III

最後的code長這樣…

#include <orb/orbit.h>
#include <ORBitservices/CosNaming.h>

void MyEatMe (PortableServer_Servant servant,
CORBA_Environment * ev)
{
/*
here is your own code which
corresponds to the object
implementation
*/
}
void MyThrowMe (PortableServer_Servant servant,
CORBA_Environment * ev)
{
/*
here is your own code which
corresponds to the object
implementation
*/
}

PortableServer_ServantBase__epv base_epv {
NULL, /* ORB specific data */
NULL, /* finalize method */
NULL /* default POA */
}

POA_FruitsBasket_Apple__epv Apple_epv {
NULL, /* ORB specific data */
MyEatMe,
MyThrowMe
};

POA_FruitsBasket_Apple__vepv Apple_vepv {
&base_epv,
&Apple_epv
};

POA_FruitsBasket_Apple Apple_servant = {
NULL,
&Apple_vpev
};

int main (int argc, char **argv)
{
CORBA_Environment ev;
CORBA_ORB orb;
PortableServer_POA root_poa;
ObjectId *obj_id;
CORBA_Object obj;
CosNaming_NamingContext *root_name;
CosNaming_NameComponent name_component[1] = { {“MyApple”, “server”} };
CosNaming_Name name = {1, 1, name_component, CORBA_FALSE};

CORBA_exception_init (&ev); /*初始化 ev 這個變數 */
orb = CORBA_ORB_init (&argc, argv, /*初始化 orb */
“orbit-local-orb”,
&ev);

POA_FruitsBasket_Apple__init (orb,
Apple_servant,
&ev);
if (ev->_major != CORBA_NO_EXCEPTION) {
fprintf (stderr,
“Error: exception during Servant initialization: %s
“,
CORBA_exception_id(&ev));
CORBA_exception_free (&ev);
exit 1;
}

root_poa = CORBA_ORB_resolve_initial_references (orb,
“RootPOA”,
&ev);
if (ev->_major != CORBA_NO_EXCEPTION) {
fprintf (stderr,
“Error: exception during RootPOA initialization: %s
“,
CORBA_exception_id(&ev));
CORBA_exception_free (&ev);
exit 1;
}

/* activate object */
obj_id = PortableServer_POA_activate_object (root_poa,
&Apple_servant,
&ev);
/* get an object reference */
obj = PortableServer_POA_id_to_reference (root_poa,/*小龍註:好像有點怪..*/
obj_id,
&ev);

/* register the object against the naming service */
root_name = CORBA_ORB_resolve_initial_service (orb,
“NameService”,
&ev);
if (ev->_major != CORBA_NO_EXCEPTION) {
fprintf (stderr,
“Error: could not get name service: %s
“,
CORBA_exception_id(&ev));
exit 1;
}
CosNaming_NamingContext_bind (root_amp,
&name,
obj,
&ev);
if (ev->_major != CORBA_NO_EXCEPTION) {
fprintf (stderr,
“Error: could not register object: %s
“,
CORBA_exception_id(&ev));
exit 1;
}
CORBA_free (root_poa);
CORBA_exception_free (&ev);
exit 0;
}

嗯…
好不容易看懂了,
但是呢, 這裡為了簡化, 全部接到rootPOA上面去…
這實在不是一個好的作法 ^^”

當你有上百個物件時這就不是一個好主意了:它們都使用同一個 POA 將導致嚴重的性能
問題。

—-
更多的函數

PortableServer_ObjectId * PortableServer_string_to_ObjectId
(CORBA_Char *string, CORBA_Environment *ev);

CORBA_Char * PortableServer_string_to_ObjectId
(PortableServer_ObjectId *obj, CORBA_Environment *ev);


kitty,kitty,kitty 三種口味,開車開車吃kitty,無聊吃kitty,
口裡芳香不口臭,你要吃kitty!!
~ kitty給我!!

夫兵者不祥之器物或惡之故有道者不處君子居則貴左用兵則貴右兵者不祥之器非君子
之器不得已相簿 http://wretch.twbbs.org/album 速度超快 50MB 網路相簿於天下
矣吉事尚左凶事尚右偏將軍居左上將軍居右言以喪禮處之殺人之眾以哀悲泣之戰勝以
喪禮處之道常無名樸雖小天下莫能臣侯王若能守之萬物將自賓天地相合以降甘露民莫
之令而自均始制有名名亦既有夫亦將知止知止可以不殆譬道pcs.csie.nctu.edu.tw海
作者在 03/12/03 17:13:10 從 pcs.csie.nctu.edu.tw 修改這篇文章






—–


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: