GNOME ����ʹ���˴����� CORBA �ӿڡ���Щ�ӿڶ�������� gnome-libs/idl �� gnome-core/idl Ŀ¼���ҵ��� �����ڸ�¼ C �б���ϸ���г���
Table 5-2. Gnome �� CORBA �ӿ�
�ӿڵ��ļ��� | �ӿڵ���; |
---|---|
desktop-viewer.idl | һϵ�ж����ı��Ķ����Ľӿڡ����磬�κ�ʵ������Щ�ӿڵ��ı��Ķ��������Ա��ļ�������������ʾ�ı��� |
desktop-editor.idl | һϵ�ж����ı��༭���Ľӿڡ�����ӿڼ̳��������Ķ����Ľӿڡ����磺�κ�ʵ������Щ�ӿڵ��ı��༭�������Ա��ļ�������������ʾ�ͱ༭�ļ��� |
Table.idl | һϵ�ж������еĽӿڡ��Ҵ�δ�����������κ�ʹ�á� |
gnome-unknown.idl | һϵ�ж��� COM δ֪�Ľӿڡ�������Ϊ bonobo ����Ļ���ʹ�á��⽫�ں���� bonobo �������ۡ� |
GnomeObject.idl | ����Ϊ bonobo ����Ļ���ʹ�á��⽫�ں���� bonobo �������ۡ� |
gnome-factory.idl | factory �����һ���Ľӿڡ� |
gnome-panel.idl | GNOME ���Ľӿڡ�����ӿ�ʵ���ϸ��Ӷ��Ӵ������Ժ��ٿ����� |
help-browser.idl | һ����ʾ�����ĵ��� HTML ������ļĽӿڡ�����ӿ��ɰ��������ʵ�֡� |
������Щ�ӿڳ������ӿڶ��������ġ����ĸ������Ǻ���Ȥ�ģ��������һЩ�� Bonobo �г��������⡣������Ҫ�������ǣ�1) �����һ��Ӧ�ó�������ʾ����һ��Ӧ�ó���(������һ����ַ�ռ�)�н����Ĺ�����2) ��ν�������ʵ����
GNOME �ṩһ�� C API ���� CORBA ���ð�װ�ɶԿ������Ѻõ� C ���á�
Factory �ӿڱ������ṩһϵ�еĹ�����ơ��� OOP �У�������������ĺ�����������������й��캯��(constructor)�����磬���ǵĵ���� Applet �������һ��������(constructor)��������������Ķ�����Factory �ӿ��ṩ���ڹ�����������һ������㡣
// The factory interface. module GNOME { typedef sequence<string> stringlist; interface GenericFactory { exception CannotActivate { }; boolean supports(in string obj_goad_id); Object create_object(in string goad_id, in stringlist params) raises(CannotActivate); }; }; |
һ������Ӧ���� GNOME::GenericFactory::create_object() ��һ��ʵ�ֵĺ����װ���Ĺ��캯���������Ϳ���Ҫ�� factory ��Ϊ�´����Ķ�������һ�� CORBA::Object ���á�������Ϊһ�� FruitsBasket::Apple �������� factory ���������롣����������� --skeleton-impl ������ orbit-idl ���ɵġ���Ϊ *__create �������ǹ��캯�������������dz�����ʵ��һ�� factory��
// idl interface #include <gnome-factory.idl> module FruitsBasket { interface AppleFactory : GNOME::GenericFactory {}; interface Apple { void EatMe (); }; }; /********** C Factory skeleton implementation ***********/ #include "apple.h" /*** App-specific servant structures ***/ typedef struct { POA_FruitsBasket_AppleFactory servant; PortableServer_POA poa; } impl_POA_FruitsBasket_AppleFactory; typedef struct { POA_FruitsBasket_Apple servant; PortableServer_POA poa; } impl_POA_FruitsBasket_Apple; /*** Implementation stub prototypes ***/ static void impl_FruitsBasket_AppleFactory__destroy(impl_POA_FruitsBasket_AppleFactory * servant, CORBA_Environment * ev); static CORBA_boolean impl_FruitsBasket_AppleFactory_supports(impl_POA_FruitsBasket_AppleFactory * servant, CORBA_char * obj_goad_id, CORBA_Environment * ev); static CORBA_Object impl_FruitsBasket_AppleFactory_create_object(impl_POA_FruitsBasket_AppleFactory * servant, CORBA_char * goad_id, GNOME_stringlist * params, CORBA_Environment * ev); static void impl_FruitsBasket_Apple__destroy(impl_POA_FruitsBasket_Apple * servant, CORBA_Environment * ev); static void impl_FruitsBasket_Apple_EatMe(impl_POA_FruitsBasket_Apple * servant, CORBA_Environment * ev); /*** epv structures ***/ static PortableServer_ServantBase__epv impl_FruitsBasket_AppleFactory_base_epv = { NULL, /* _private data */ NULL, /* finalize routine */ NULL, /* default_POA routine */ }; static POA_FruitsBasket_AppleFactory__epv impl_FruitsBasket_AppleFactory_epv = { NULL, /* _private */ }; static POA_GNOME_GenericFactory__epv impl_FruitsBasket_AppleFactory_GNOME_GenericFactory_epv = { NULL, /* _private */ (gpointer) & impl_FruitsBasket_AppleFactory_supports, (gpointer) & impl_FruitsBasket_AppleFactory_create_object, }; static PortableServer_ServantBase__epv impl_FruitsBasket_Apple_base_epv = { NULL, /* _private data */ NULL, /* finalize routine */ NULL, /* default_POA routine */ }; static POA_FruitsBasket_Apple__epv impl_FruitsBasket_Apple_epv = { NULL, /* _private */ (gpointer) & impl_FruitsBasket_Apple_EatMe, }; /*** vepv structures ***/ static POA_FruitsBasket_AppleFactory__vepv impl_FruitsBasket_AppleFactory_vepv = { &impl_FruitsBasket_AppleFactory_base_epv, &impl_FruitsBasket_AppleFactory_GNOME_GenericFactory_epv, &impl_FruitsBasket_AppleFactory_epv, }; static POA_FruitsBasket_Apple__vepv impl_FruitsBasket_Apple_vepv = { &impl_FruitsBasket_Apple_base_epv, &impl_FruitsBasket_Apple_epv, }; /*** Stub implementations ***/ /* This is the Factory constructor. * It must be called from the main function so that * factory can create new Apple objects */ static FruitsBasket_AppleFactory impl_FruitsBasket_AppleFactory__create(PortableServer_POA poa, CORBA_Environment * ev) { FruitsBasket_AppleFactory retval; impl_POA_FruitsBasket_AppleFactory *newservant; PortableServer_ObjectId *objid; newservant = g_new0(impl_POA_FruitsBasket_AppleFactory, 1); newservant->servant.vepv = &impl_FruitsBasket_AppleFactory_vepv; newservant->poa = poa; POA_FruitsBasket_AppleFactory__init((PortableServer_Servant) newservant, ev); objid = PortableServer_POA_activate_object(poa, newservant, ev); CORBA_free(objid); retval = PortableServer_POA_servant_to_reference(poa, newservant, ev); return retval; } static void impl_FruitsBasket_AppleFactory__destroy(impl_POA_FruitsBasket_AppleFactory * servant, CORBA_Environment * ev) { PortableServer_ObjectId *objid; objid = PortableServer_POA_servant_to_id(servant->poa, servant, ev); PortableServer_POA_deactivate_object(servant->poa, objid, ev); CORBA_free(objid); POA_FruitsBasket_AppleFactory__fini((PortableServer_Servant) servant, ev); g_free(servant); } static CORBA_boolean impl_FruitsBasket_AppleFactory_supports(impl_POA_FruitsBasket_AppleFactory * servant, CORBA_char * obj_goad_id, CORBA_Environment * ev) { CORBA_boolean retval; return retval; } static CORBA_Object impl_FruitsBasket_AppleFactory_create_object(impl_POA_FruitsBasket_AppleFactory * servant, CORBA_char * goad_id, GNOME_stringlist * params, CORBA_Environment * ev) { CORBA_Object retval; /* here, the only things to do are to create or reuse * a poa and a poamanager and register with them * the Apple thanks to the * impl_FruitsBasket_Apple__create */ retval = impl_FruitsBasket_Apple__create (servant->poa, ev); return retval; } /* This is the Apple constructor which just needs to be * called by the create_object function of the factory * instead of being directly called by the main function */ static FruitsBasket_Apple impl_FruitsBasket_Apple__create(PortableServer_POA poa, CORBA_Environment * ev) { FruitsBasket_Apple retval; impl_POA_FruitsBasket_Apple *newservant; PortableServer_ObjectId *objid; newservant = g_new0(impl_POA_FruitsBasket_Apple, 1); newservant->servant.vepv = &impl_FruitsBasket_Apple_vepv; newservant->poa = poa; POA_FruitsBasket_Apple__init((PortableServer_Servant) newservant, ev); objid = PortableServer_POA_activate_object(poa, newservant, ev); CORBA_free(objid); retval = PortableServer_POA_servant_to_reference(poa, newservant, ev); return retval; } static void impl_FruitsBasket_Apple__destroy(impl_POA_FruitsBasket_Apple * servant, CORBA_Environment * ev) { PortableServer_ObjectId *objid; objid = PortableServer_POA_servant_to_id(servant->poa, servant, ev); PortableServer_POA_deactivate_object(servant->poa, objid, ev); CORBA_free(objid); POA_FruitsBasket_Apple__fini((PortableServer_Servant) servant, ev); g_free(servant); } static void impl_FruitsBasket_Apple_EatMe(impl_POA_FruitsBasket_Apple * servant, CORBA_Environment * ev) { } void main (int argc, char **argv) { CORBA_Environment ev; CORBA_ORB orb; CORBA_Object root_poa; PortableServer_POAManager root_poa_manager; CosNaming_NamingContext name_server; CORBA_Object obj; CORBA_exception_init (&ev); orb = gnome_CORBA_init ("An Apple", "1.0", &argc, argv, GNORBA_INIT_SERVER_FUNC, &ev); root_poa = CORBA_ORB_resolve_initial_references (orb, "RootPOA", &ev); root_poa_manager = PortableServer_POA__get_the_POAManager ( (PortableServer_POA) root_poa, &ev); PortableServer_POAManager_activate (root_poa_manager, &ev); /* this function will create all the other * needed interfaces */ obj = impl_FruitsBasket_AppleFactory__create ((PortableServer_POA) root_poa, &ev); /* register against the GOAD */ name_server = gnome_name_service_get (); /* This is really important: make sure you use these 2 functions when registering */ goad_server_register (name_server, obj, goad_server_activation_id(), "server", &ev); /* finished !! */ CORBA_exception_free (&ev); gtk_main (); return 0; } |
һ��������һ���Ѿ�ʵ�ֵ� CORBA::Object��һ��ֻ�ü����Ӿ�������һ�� factory ��֧�������� main ������ԭ�����������е��������ڶ��� GNOME::GenericFactory::create_object ��ʵ�������ˣ����� main �����е�ԭ���Ķ���һ�� GNOME::GenericFactory �������滻��
Ψһ���ѵ�������ʹ�� goad_server_register �������ַ�����ע�Ტ�� goad_server_activation_id ���õ���ȷ��ע�����֡�
������ Factory ֧��֮ǰ������������ apple.gnorba �ļ�����������Ҫһ���µ� apple.gnorba �ļ���
# old .gnorba file [Apple] type=exe repo_id=IDL:GNOME/Apple:1.0 description=A nice Apple location_info=apple |
#new .gnorba file [Apple_factory] type=exe repo_id=IDL:GNOME/GenericFactory:1.0 description=internal location_info=apple [Apple] type=factory repo_id=IDL:GNOME/Apple:1.0 description=A nice Apple location_info=Apple_factory |
Ϊ������ apple.gnorba �ļ����������汾��������������쿴 GOAD Դ���롣
�ڵ�һ���������������� GoadServer �ϵ��� goad_server_activate ���� Apple��GOAD ������ goad_server_activate_exe ������ GOAD ���ڲ����������� location_info ������ִ�� fork/exec �������������� apple ����ʵ����(instantiate)���ǵĶ����һ���������ʹӲ��ҽ������ַ�����ע������ GOAD ����һ���ȴ��µ� CORBA::Object ��ע���ѭ�������п��ܵģ���ʵ������ʹ��һ���ܵ�����ȡ���ǵĿͻ��� stdout ������� IOR �ַ���(���Ƿdz���Ч�ġ� dixit Eliot Lee, ���������)��
�ڵڶ����������������� GoadServer �ϵ��� goad_server_activate ���� Apple��GOAD ������ goad_server_activate_factory��������һ�� GOAD ���ڲ��������������������ȷ�� factory ���ð� Apple location_info �ֶε��� goad_server_activate_with_id �����ġ� ��� factory û�����У��� ���� goad_server_activate_exe ������ Apple_factory �������� ���� goad_server_activate_factory �������ŵ��� goad_server_activate_with_id ���ص� factory ����� create_object ������
��ǿ�ҽ�����鿴 gnome-libs/libgnorba/goad.c �������ʹ���ŷ�����������
�������ϣ�ʹ�� factory �dz��õIJ��Ҳ��úܶ��������ʱ�DZ���IJ��ṩ������ô��������ѵ����������� .gnorba �ļ���ȷ����ϸ����ڣ�����ȥֻҪ���о��ܹ�����Ҫע�⣬���� applet ����һЩ C API ������ʹ factory ������ʹ�ã� applet_factory_new �������е�һ����
GNOME ����������ӿڣ� GNOME::Panel��GNOME::PanelSpot �� GNOME::Applet��GNOME::Panel �� PanelSpot ���뱻�������ʵ�֣��� GNOME::Applet Ӧ���� Applet ����ʵ�֡�
���ӿڶ������£�
module GNOME { struct Color { unsigned short red, green, blue; }; typedef short AppletId; typedef short PanelId; interface Panel { enum OrientType { ORIENT_UP, ORIENT_DOWN, ORIENT_LEFT, ORIENT_RIGHT }; enum BackType { BACK_NONE, BACK_COLOR, BACK_PIXMAP }; union BackInfoType switch(BackType) { case BACK_COLOR: Color c; case BACK_PIXMAP: string pmap; }; enum SizeType { SIZE_TINY, SIZE_STANDARD, SIZE_LARGE, SIZE_HUGE }; PanelSpot add_applet(in Applet panel_applet, in string goad_id, out string cfgpath, out string globcfgpath, out unsigned long winid); oneway void quit (); readonly attribute boolean in_drag; }; }; |
����ӿڽ���ʼ��һ�� Applet Ҫ��֮�Ի��� GNOME::PanelSpot���뷨�� applet ���챻��ʾ�Ĺ��������� applet һ�������滭�����Ĵ��ڡ�applet Ҳ������嵱������Ҽ�ʱӦ����ʾ�IJ˵���Ŀ�������� applet ������IJ˵���Ŀ�������Ϳ��Ե�����ȷ�Ļص�������������Щ����ͨ�� PanelSpot �� Applet �ӿ���ɡ�
�������һ�� applet���ұ�������ȷ����ʵ�ֵ� Applet �ӿ��Ѿ������˲��� ORB ��ע���ˡ������ҵ��� GNOME::Panel::add_applet ���������������Ҫ������ϳ��֡�
�ȴ����أ���������һ�� GNOME::PanelSpot �ӿں�һ�� unsigned long winid��
GTK �� Plug �� Socket ���������ڰ���� winid ת����һЩ���õĶ�����Socket ����������һ������������Ի������Ĵ��ڡ��� GTK_WINDOW_XWINDOW(widget) �� (from gtk/gtkx.h) �� Socket ����ת����һ�� winid��Plug ����������� winid ����ת��һ�� GtkWidget�� applet Ҫ��������ϵ�һ������ʱ����彨��һ�� socket ���� applet ���� winid ������ applet ������Ӧ�� gtk_plug �����������Լ��Ĺ�����
��Ϊ�����Ŷ���������������ι����ģ�gtk_plug/gtk_socket/winid ϵͳ�Ƿdz���Ҫ�ģ���д��һЩ���Դ��롣(�μ���¼ D)
���˵��ǣ�������Щ�����Զ�������Ϊ Applet �ӿ���Ƶ� C API �����ĺ��档
Ҫ�����Ҽ������IJ˵�������Ҫ��һЩ������������ Socket �����ϵ��¼������͵� socket �����������������滭������ plug ����һ����֪������ζ�� socket ������ plug �����ʹ��� socket �����ڲ���Ӧ�ó����¼����¼����뱻��һ��ϵͳ�������һ��¼���ͨ������Ľӿڴ�����
module GNOME { interface PanelSpot { // gosh !! i removed many things from here !! oneway void add_callback (in string callback_name, in string stock_item, in string menuitem_text); oneway void remove_callback (in string callback_name); }; interface Applet { // gosh !! i removed many things from here !! oneway void do_callback (in string callback_name); }; }; |
Ҫע��ӿ������Ķ��������ǵ���ģ�����Ϊ�˽�ʡ���������ϵͳ���ء�
Applet ������GNOME::PanelSpot::add_callback �� GNOME::PanelSpot::add_callback ���쵱����һ�ʱ����ʾ�IJ˵������ţ����û���һ���˵���Ŀ�ϵ��ʱ����彫���� GNOME::Applet::do_callback��
PanelSpot �� Applet �ӿڱ�����������ʾ��Ҫ�����ࣺ����Ҫ�����������������飺��λ�������С�������������ʾ������ɫ/pixmap... �Ұ�ʣ�µ�Ҫ��ʱ��鿴�Ķ��������ˣ����ڶ��Ǻ����� :)
��һ�������˵ģ����е� CORBA �ĸ����Զ������ڻ����ٵİ�װ CORBA ����� C �����ĺ��档 libapplet ��������ڸ�����ġ�(gnome-core/panel/applet-widget.c and applet-widget.h)