Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / utils / NamingViewer / ViewIORDialog.cpp
blobb3bc5f4f7644a36ee5ec02156d1fccf69f0d93e2
1 #include "stdafx.h"
2 #include "NamingViewer.h"
3 #include "ViewIORDialog.h"
4 #include "tao/IIOP_Profile.h"
5 #include "tao/Stub.h"
7 #ifdef _DEBUG
8 #define new DEBUG_NEW
9 #undef THIS_FILE
10 static char THIS_FILE[] = __FILE__;
11 #endif
13 /////////////////////////////////////////////////////////////////////////////
14 // ViewIORDialog dialog
17 ViewIORDialog::ViewIORDialog(CORBA::ORB_ptr pORB, CORBA::Object_ptr pObject, CWnd* pParent /*=NULL*/)
18 : CDialog(ViewIORDialog::IDD, pParent)
20 //{{AFX_DATA_INIT(ViewIORDialog)
21 m_TypeID = _T("");
22 m_IOR = _T("");
23 //}}AFX_DATA_INIT
24 m_pORB = pORB;
25 if(pObject)
27 m_Object = CORBA::Object::_duplicate(pObject);
29 CORBA::String_var IOR = pORB->object_to_string(pObject);
30 m_IOR = IOR;
34 void ViewIORDialog::DoDataExchange(CDataExchange* pDX)
36 CDialog::DoDataExchange(pDX);
37 //{{AFX_DATA_MAP(ViewIORDialog)
38 DDX_Control(pDX, IDC_PROFILES, m_Profiles);
39 DDX_Text(pDX, IDC_TYPE_ID, m_TypeID);
40 DDX_Text(pDX, IDC_IOR, m_IOR);
41 //}}AFX_DATA_MAP
45 BEGIN_MESSAGE_MAP(ViewIORDialog, CDialog)
46 //{{AFX_MSG_MAP(ViewIORDialog)
47 ON_BN_CLICKED(IDC_APPLY, OnApply)
48 //}}AFX_MSG_MAP
49 END_MESSAGE_MAP()
51 /////////////////////////////////////////////////////////////////////////////
52 // ViewIORDialog message handlers
54 BOOL ViewIORDialog::OnInitDialog()
56 CDialog::OnInitDialog();
58 // TODO: Add extra initialization here
59 DecodeIOR();
60 return TRUE; // return TRUE unless you set the focus to a control
61 // EXCEPTION: OCX Property Pages should return FALSE
64 void ViewIORDialog::OnApply()
66 // TODO: Add your control notification handler code here
67 UpdateData();
68 try
70 m_Object = m_pORB->string_to_object(m_IOR);
71 DecodeIOR();
73 catch(CORBA::Exception& ex)
75 MessageBox(ACE_TEXT_CHAR_TO_TCHAR (ex._rep_id()), ACE_TEXT ("CORBA::Exception"));
79 void ViewIORDialog::DecodeIOR()
81 // Reset the fields
82 m_Profiles.DeleteAllItems();
83 m_TypeID = "";
84 UpdateData(FALSE);
86 // if object is nil, return out
87 if(CORBA::is_nil(m_Object))
89 return;
92 // Get the stub
93 TAO_Stub* pStub = m_Object->_stubobj();
94 const char* pType = pStub->type_id;
95 m_TypeID = pType ? pType : ""; // special case for INS objects, tao doesn't get the type id
96 UpdateData(FALSE);
98 // Iterate through each profile and add an entry to the tree control
99 const TAO_MProfile& BaseProfiles= pStub->base_profiles();
100 CORBA::ULong const Count = BaseProfiles.profile_count();
101 for(CORBA::ULong Slot = 0; Slot < Count; Slot++)
103 const TAO_Profile* pProfile = BaseProfiles.get_profile(Slot);
104 HTREEITEM hProfile;
105 switch(pProfile->tag())
107 case 0: //IOP::TAG_INTERNET_IOP:
109 TAO_IIOP_Profile* pIIOPProfile = (TAO_IIOP_Profile*)pProfile;
110 CString ProfileString;
111 ProfileString.Format(ACE_TEXT ("IIOP %d.%d"),
112 pIIOPProfile->version().major,
113 pIIOPProfile->version().minor);
114 hProfile = m_Profiles.InsertItem(ProfileString);
115 TAO_IIOP_Endpoint* pIIOPEndpoint =
116 (TAO_IIOP_Endpoint*)pIIOPProfile->endpoint ();
117 while(pIIOPEndpoint)
119 CString EndpointString;
120 EndpointString.Format(ACE_TEXT ("%s:%d"),
121 pIIOPEndpoint->host(),
122 pIIOPEndpoint->port());
123 HTREEITEM hItem = m_Profiles.InsertItem(EndpointString, hProfile);
124 m_Profiles.EnsureVisible(hItem);
125 pIIOPEndpoint = (TAO_IIOP_Endpoint*)pIIOPEndpoint->next();
129 break;
130 default:
132 CString ProfileString;
133 char* pToString = ((TAO_Profile*)pProfile)->to_string();
134 ProfileString.Format(ACE_TEXT ("Unknown Profile (Tag=%d) %s"), pProfile->tag(), pToString);
135 delete pToString;
136 hProfile = m_Profiles.InsertItem(ProfileString);
138 break;