Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / examples / mfc / server.cpp
blob20b6e8fe2f528e6dd6cdf2ad4d9d9f64df3ac380
1 // server.cpp : Defines the class behaviors for the application.
3 #include "stdafx.h"
4 #include "server.h"
6 // Demospecific includes
7 #include "w32_test_impl.h"
8 // Demospecific includes end!
10 #include "MainFrm.h"
11 #include "serverDoc.h"
12 #include "serverView.h"
14 #include "ace/ACE.h"
15 #include "ace/Init_ACE.h"
17 #ifdef _DEBUG
18 #define new DEBUG_NEW
19 #undef THIS_FILE
20 static char THIS_FILE[] = __FILE__;
21 #endif
24 /////////////////////////////////////////////////////////////////////////////
25 // CServerApp
27 BEGIN_MESSAGE_MAP(CServerApp, CWinApp)
28 //{{AFX_MSG_MAP(CServerApp)
29 ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
30 // NOTE - the ClassWizard will add and remove mapping macros here.
31 // DO NOT EDIT what you see in these blocks of generated code!
32 //}}AFX_MSG_MAP
33 // Standard file based document commands
34 ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
35 ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
36 // Standard print setup command
37 ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
38 END_MESSAGE_MAP()
41 // Thread-Function!
42 static unsigned long
43 spawn_my_orb_thread (void *)
45 try
47 CORBA::ORB_var the_orb = CORBA::ORB_init (__argc, __argv);
49 CORBA::Object_var orb_obj =
50 the_orb->resolve_initial_references ("RootPOA");
52 PortableServer::POA_var the_root_poa =
53 PortableServer::POA::_narrow (orb_obj.in ());
55 PortableServer::POAManager_var the_poa_manager =
56 the_root_poa->the_POAManager ();
58 the_poa_manager->activate ();
60 // Initializing the NamingService
61 W32_Test_Impl myservant;
62 W32_Test_Interface_var orb_servant =
63 myservant._this ();
65 CORBA::String_var ior =
66 the_orb->object_to_string (orb_servant.in ());
68 FILE *output_file = ACE_OS::fopen ("ior.txt", "w");
69 ACE_OS::fprintf (output_file,
70 "%s",
71 ior.in ());
72 ACE_OS::fclose (output_file);
74 the_orb->run ();
76 catch (const CORBA::Exception& ex)
78 ex._tao_print_exception ("Caught exception:");
79 return 0;
82 return 0;
85 /////////////////////////////////////////////////////////////////////////////
86 // CServerApp construction
88 CServerApp::CServerApp()
90 // TODO: add construction code here,
91 // Place all significant initialization in InitInstance
95 CServerApp::~CServerApp()
97 try
99 CORBA::ORB_var the_shutdown_orb;
101 int argc = 0;
102 ACE_TCHAR **argv = 0;
103 const ACE_TCHAR *orb_name = ACE_TEXT("");
105 // Retrieving a reference to the ORB used inside the thread
106 the_shutdown_orb =
107 CORBA::ORB_init (argc,
108 argv,
109 orb_name);
111 the_shutdown_orb->shutdown (false);
113 ACE_Thread_Manager::instance ()->wait ();
115 catch (const CORBA::Exception& ex)
117 ex._tao_print_exception ("Caught exception:");
121 ACE::fini ();
124 /////////////////////////////////////////////////////////////////////////////
125 // The one and only CServerApp object
127 CServerApp theApp;
129 /////////////////////////////////////////////////////////////////////////////
130 // CServerApp initialization
132 BOOL CServerApp::InitInstance()
134 ACE::init();
136 AfxEnableControlContainer();
138 // Standard initialization
139 // If you are not using these features and wish to reduce the size
140 // of your final executable, you should remove from the following
141 // the specific initialization routines you do not need.
144 From MFC 5.0, Enable3dControls and Enable3dControlsStatic are obsolete
145 because their functionality is incorporated into Microsoft's 32-bit
146 operating systems. Basically no need to call with VC5.0 and above.
148 #if !defined (_WIN32_WCE)
149 #ifdef _AFXDLL
150 Enable3dControls(); // Call this when using MFC in a shared DLL
151 #else
152 Enable3dControlsStatic(); // Call this when linking to MFC statically
153 #endif
154 #endif
157 // Change the registry key under which our settings are stored.
158 // TODO: You should modify this string to be something appropriate
159 // such as the name of your company or organization.
160 SetRegistryKey(_T("Local AppWizard-Generated Applications"));
162 LoadStdProfileSettings(); // Load standard INI file options (including MRU)
164 // Register the application's document templates. Document templates
165 // serve as the connection between documents, frame windows and views.
167 CSingleDocTemplate* pDocTemplate;
168 pDocTemplate = new CSingleDocTemplate(
169 IDR_MAINFRAME,
170 RUNTIME_CLASS(CServerDoc),
171 RUNTIME_CLASS(CMainFrame), // main SDI frame window
172 RUNTIME_CLASS(CServerView));
173 AddDocTemplate(pDocTemplate);
175 // Parse command line for standard shell commands, DDE, file open
176 CCommandLineInfo cmdInfo;
177 ParseCommandLine(cmdInfo);
179 // Dispatch commands specified on the command line
180 if (!ProcessShellCommand(cmdInfo))
181 return FALSE;
183 // The one and only window has been initialized, so show and update it.
184 m_pMainWnd->ShowWindow(SW_SHOW);
185 m_pMainWnd->UpdateWindow();
187 ACE_Thread_Manager::instance()->spawn (spawn_my_orb_thread);
189 return TRUE;
193 /////////////////////////////////////////////////////////////////////////////
194 // CAboutDlg dialog used for App About
196 class CAboutDlg : public CDialog
198 public:
199 CAboutDlg();
201 // Dialog Data
202 //{{AFX_DATA(CAboutDlg)
203 enum { IDD = IDD_ABOUTBOX };
204 //}}AFX_DATA
206 // ClassWizard generated virtual function overrides
207 //{{AFX_VIRTUAL(CAboutDlg)
208 protected:
209 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
210 //}}AFX_VIRTUAL
212 // Implementation
213 protected:
214 //{{AFX_MSG(CAboutDlg)
215 // No message handlers
216 //}}AFX_MSG
217 DECLARE_MESSAGE_MAP()
220 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
222 //{{AFX_DATA_INIT(CAboutDlg)
223 //}}AFX_DATA_INIT
226 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
228 CDialog::DoDataExchange(pDX);
229 //{{AFX_DATA_MAP(CAboutDlg)
230 //}}AFX_DATA_MAP
233 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
234 //{{AFX_MSG_MAP(CAboutDlg)
235 // No message handlers
236 //}}AFX_MSG_MAP
237 END_MESSAGE_MAP()
239 // App command to run the dialog
240 void CServerApp::OnAppAbout()
242 CAboutDlg aboutDlg;
243 aboutDlg.DoModal();
246 /////////////////////////////////////////////////////////////////////////////
247 // CServerApp message handlers