CosNaming ģ����ʵ�� CORBA ���ַ����ģ�顣������ÿ������ͬһ���ɱ����Ķ����ַ�������(associate)��һ������ַ�������������Ҫʱ�ҵ��������á��⾫ȷ�������� DNS��DNS �������һ������ www.mathieu.rezel.enst.fr �����в�ε����������õ� IP ��ַ 137.194.8.56 ������һ��
�������"GNOME.servers.Panel"���������ֱ�����ע��������á����͵ģ�������ע��һ�����֣��ͻ��������������һ�������Ƿ�ע���ˡ������ע���ˣ��ͻ�����������õ��������������á��������������������
������һЩ�ض��� CORBA ��������Ĵʻ㣺��������һ���������������а�(bound)������������ϵġ�����һ����������һ�����������������ҵ���һ�������ϵĶ������á��������� CORBA �������ǿ�������������һ�����������ڽ�������ͼ������ͼ��ÿ���ڵ���һ�����������Ķ�����Ҷ�����Լ��ĵĶ����һ�����������ɽڵ����ֺ���Ҷ������ɵĸ������֣�������������ͼ�дӸ��������·��������ġ����磬GNOME ������ͼ�Ǻܼġ������� root -> GNOME -> servers ��
GNOME Panel �ĸ���������: root -> GNOME -> servers -> Panel ��
������ CosNaming �� IDL:
module CosNaming {
typedef string Istring;
struct NameComponent {
Istring id;
Istring kind;
};
typedef sequence<NameComponent> Name;
enum BindingType {
nobject,
ncontext
};
struct Binding {
Name binding_name;
BindingType binding_type;
};
interface NamingContext {
void bind(in Name n, in Object obj)
raises(NotFound,
CannotProceed,
InvalidName,
AlreadyBound);
void rebind(in Name n, in Object obj)
raises(NotFound,
CannotProceed,
InvalidName);
void bind_context(in Name n, in NamingContext nc)
raises(NotFound,
CannotProceed,
InvalidName,
AlreadyBound);
void rebind_context(in Name n, in NamingContext nc)
raises(NotFound,
CannotProceed,
InvalidName);
Object resolve(in Name n)
raises(NotFound,
CannotProceed,
InvalidName);
void unbind(in Name n)
raises(NotFound,
CannotProceed,
InvalidName);
NamingContext new_context();
NamingContext bind_new_context(in Name n)
raises(NotFound,
AlreadyBound,
CannotProceed,
InvalidName);
void destroy()
raises(NotEmpty);
};
}; |
Ϊ��ʹ������������ҹ���Ĵ������Ľӿ���ɾ����һЩ���塣(������ģ�鶨�������������ܷdz�����)
�����ṩ�˽�������ͼ�ĺ�����bind��rebind �� unbind �������ڸ����������н������ְ�(���������㽨������ͼ�е���Ҷ)��
bind_context��rebind_context��new_context �� bind_new_context �����㽨������������(���������㽨������ͼ�Ľڵ�)��
������������ø���������������ͼ�еõ��������á�
�����ǰ�һ�����ֵ�һ������ķ��������룺
/* ���� Panel ��һЩ���룬��������ʱִ��
* �����ַ���ע��
*/
main ()
{
CORBA_Object orb;
CORBA_Environment ev;
CosNaming_NamingContext root;
CosNaming_NameComponent name_component[3] = { {"GNOME", "subcontext"},
{"Servers", "subcontext"}
{"gnome_panel", "server"} };
CosNaming_Name name = {3, 3, name_component, CORBA_FALSE};
CORBA_Object panel;
CORBA_exception_init (&ev);
CORBA_ORB_init (&ev);
root = CORBA_ORB_resolve_initial_service (orb,
"NameService",
&ev);
if (ev->_major != CORBA_NO_EXCEPTION) {
fprintf (stderr,
"Error: could not get name service: %s\n",
CORBA_exception_id(&ev));
exit (1);
}
/* ������, һЩ������ ORB ע�������
* �������洢�� panel �е���Ч�Ķ�������
* �⽫�ڵ� 4 ��: POA �н���
*/
CosNaming_NamingContext_bind (root, &name, panel, &ev);
if (ev->_major != CORBA_NO_EXCEPTION) {
fprintf (stderr,
"Error: could register object: %s\n",
CORBA_exception_id(&ev));
exit (1);
}
CORBA_exception_free (&ev);
return 0;
} |
�����ǽ������������ֵĿͻ����롣
#include <corba.h>
int main (int argc, char *argv)
{
CORBA_Object orb;
CORBA_Environment ev;
CosNaming_NamingContext *root;
CosNaming_NameComponent name_component[3] = { {"GNOME", "subcontext"},
{"Servers", "subcontext"}
{"gnome_panel", "server"} };
CosNaming_Name name = {3, 3, name_component, CORBA_FALSE};
CORBA_Object panel;
CORBA_exception_init (&ev);
CORBA_ORB_init (&ev);
root = CORBA_ORB_resolve_initial_service (orb,
"NameService",
&ev);
if (ev->_major != CORBA_NO_EXCEPTION) {
fprintf (stderr,
"Error: could not get name service: %s\n",
CORBA_exception_id(&ev));
exit (1);
}
panel = CosNaming_NamingContext_resolve (root,
&name,
&ev);
if (ev->_major != CORBA_NO_EXCEPTION) {
fprintf (stderr,
"Error: could resolve object: %s\n",
CORBA_exception_id(&ev));
exit (1);
}
/* ������, panel ��������һ���� GNOME panel �� CORBA_Object��
* ���Ե���һЩ�� gnome-core/idl/gnome-panel.idl �ж���� panel ����
*/
CORBA_free (root);
CORBA_exception_free (&ev);
return 0;
} |
CosNaming_NameComponent �� CosNaming_Name �ṹ���� CosNaming ģ���е���Ӧ�� IDL �����ֱ�� C ӳ�䡣
��ע�⣬����ͻ���֪����ȷ�ķ����������֣�������ʹ�� list �������õ�һ�������İ�һ���б���
һ����δ��������⣺����Щ���������У�һ�������ļٶ��������Ѿ���ʼʹ��һ���� NameService �� NamingContext ������������εõ�����? ��Ϊ���ض��ij�ʼ������ CORBA_ORB_init������Ψһ�ܷ��ʵĶ����� ORB��
��ʵ�ϣ��� ORB �ӿ���һ������ķ����������õ�һ����һ�����������ĵij�ʼ���ã����������������������֡�
���������� IDL��
module CORBA {
interface ORB {
typedef string ObjectId;
typedef sequence <ObjectId> ObjectIdList;
ObjectIdList list_initial_services ();
exception InvalidName {};
Object resolve_initial_reference (in ObjectId identifier)
raises (InvalidName);
};
}; |
ORB ��������Ȥ�ķ�����list_initial_services �� resolve_initial_reference����һ��������� ORB ���Խ����ġ��ɵõ��ķ����һ���б����� CORBA 2.2 �淶�У����з����DZ��ģ�"RootPoa"�� "POACurrent"��"InterfaceRepository"��"NameService"��"TradingService"��"SecurityCurrent" �� "TransactionCurrent"������ζ�Ŷ�һ�� CORBA 2.2 ORB ��������ý�������Щ�ַ�����һ���б������д�������Ļ����ʾ ORBit �пɵõ��ķ�����б���
#include <corba.h>
int main (int argc, char **argv)
{
CORBA_ORB orb;
CORBA_Environment ev;
CORBA_sequence_ObjectId *seq;
CORBA_unsigned_long i;
CORBA_exception_init (&ev);
orb = CORBA_ORB_init (&ev);
seq = CORBA_ORB_list_initial_services (orb, &ev);
for (i=0; i<seq->_lenght ;i++) {
fprintf (stdout, "%s\n" ,(seq->_buffer)[i]);
}
return 0;
} |
resolve_initial_service ����������Ϊ�������ݸ������ַ�����Ӧ�Ķ������á�����������õ�����������Ķ������á��ڵ��� CORBA_ORB_resolve_initial_service (orb, "NameService", &ev) ֮ǰ���㲻�ܷ����κζ���(������ʹ�� IOR �ַ�����������ҪһЩǰ����Ҳ�����Ĺ���)������������һ����һ�����������ĵĶ������ã������������һ���������Ϳ���ע�����������������ǿͻ�����ö����������ĵõ�һ���������������á�
ע��: ��Щ����Ψһ����������Ȼ���ܹ����� ORBit ��һ�� NameService��ͨ��������Ӧ��"orbit-name-server"�ػ�����������������ַ�����������ַ�����ͨ����� CORBA_ORB_init ����������������Ҫʹ�������ַ���������ʱ��ʾ�����ַ������� IOR �ַ���������ʹ�õķ��������������ػ����̣�"orbit-name-server >/tmp/name-service-ior &"���⽫�� /tmp/name-service-ior �ļ��д洢 IOR �ַ�������� IOR �ַ���������������������ǰ�о��Ĵ�������ȡ��
��ע������ CORBA_ORB_init ���ڵij������걸����μ��෭��� ORBit FAQ��
GNOME ͨ�� gnome_get_name_service API �����dz������Ľ����������⣬����������ں�����½ڽ��⡣
| Prev | Home | Next |
| Some useful standardized interfaces | Up | The Interface Repository interface |