ICP  1
isisdatasvr.cpp
Go to the documentation of this file.
1 // isisdatasvr.cpp : Implementation of WinMain
2 
3 
4 #include "stdafx.h"
5 #include "resource.h"
6 #include "isisdatasvr_i.h"
7 #include "ISISDS.h"
8 #include "isisdatasvr_extMC.h"
9 
10 
11 class CisisdatasvrModule : public ATL::CAtlServiceModuleT< CisisdatasvrModule, IDS_SERVICENAME >
12  {
13 public :
14  DECLARE_LIBID(LIBID_isisdatasvrLib)
15 // DECLARE_REGISTRY_APPID_RESOURCEID(IDR_ISISDATASVR, "{0C3F2EC0-7232-429B-B58F-61719B6BBFBC}")
16  DECLARE_REGISTRY_APPID_RESOURCEID(IDR_ISISDATASVR, "{30E8C5AF-52D0-4FCB-AF0A-2E3EE7A392C8}") // the original
17 
18  HRESULT InitializeSecurity() throw()
19  {
20  // TODO : Call CoInitializeSecurity and provide the appropriate security settings for
21  // your service
22  // Suggested - PKT Level Authentication,
23  // Impersonation Level of RPC_C_IMP_LEVEL_IDENTIFY
24  // and an appropiate Non NULL Security Descriptor.
25 
26  return S_OK;
27  }
28  HRESULT Start(int nShowCmd) throw();
29  HRESULT OnStop();
30  };
31 
32 CisisdatasvrModule _AtlModule;
33 
34 class ISISDataSvrApp : public Poco::Util::Application
35 {
36  int m_nShowCmd;
37 public:
38  ISISDataSvrApp(int nShowCmd) : Poco::Util::Application(), m_nShowCmd(nShowCmd) { }
39  virtual int main(const std::vector<std::string>& args);
40 protected:
41  void initialize(Poco::Util::Application& self)
42  {
43  registerExtraLoggerChannels();
44  if (loadAppConfig("isisdatasvr") != 0) // does equivalent job of default loadConfiguration()
45  {
46 // LogEventEx(ICP_MSG_ERROR, "Cannot load isisicp.default.properties", EVENTLOG_ERROR_TYPE);
47  throw std::exception("Cannot load isisdatasvr.default.properties");
48  }
49  Application::initialize(self);
50  }
51 };
52 
53 int ISISDataSvrApp::main(const std::vector<std::string>& args)
54 {
55  return _AtlModule.WinMain(m_nShowCmd);
56 }
57 
58 static ISISDataSvrApp* the_app = NULL;
59 
60 //
61 extern "C" int WINAPI _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/,
62  LPTSTR lpCmdLine, int nShowCmd)
63 {
64  std::vector<std::string> args;
65  if ( !stricmp(lpCmdLine, "/RegServer") )
66  {
67  return 0; // we are not a com server and may hang?
68  }
69  args.push_back("isisdatasvr.exe");
70  the_app = new ISISDataSvrApp(nShowCmd);
71  the_app->init(args);
72  int ret = the_app->run();
73  delete the_app;
74  the_app = 0;
75  return ret;
76 }
77 
78 HRESULT CisisdatasvrModule::Start(int nShowCmd) throw()
79 {
80  InitializeCom();
81  m_dwTimeOut = 0; // so we do not terminate when there are no active commections
82  Poco::NamedMutex proc_lock("ISISDATASVR_PROCESS_LOCK");
83  if ( !proc_lock.tryLock() )
84  {
85  return E_FAIL;
86  }
87  m_ds = new ISISDS();
88  m_ds->start();
89 // LogEvent("starting");
90  the_app->logger().information("Starting isisdatasvr");
91  while(m_ds->isRunning())
92  {
93  Sleep(1000);
94  }
95  return CAtlServiceModuleT<CisisdatasvrModule,IDS_SERVICENAME>::Start(nShowCmd);
96 }
97 
98 HRESULT CisisdatasvrModule::OnStop()
99 {
100  the_app->logger().information("Stopping isisdatasvr");
101  if (m_ds != NULL)
102  {
103  delete m_ds;
104  m_ds = NULL;
105  }
106  return S_OK;
107 }
#define IDR_ISISDATASVR
Definition: Resource.h:7
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_ISISDATASVR,"{30E8C5AF-52D0-4FCB-AF0A-2E3EE7A392C8}") HRESULT InitializeSecurity()
Definition: isisdatasvr.cpp:16