1 //===-- MIUtilSingletonHelper.h ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
16 #include "MIUtilString.h"
17 #include "MICmnResources.h"
19 //++ ============================================================================
20 // Details: Short cut helper function to simplify repeated initialisation of
21 // MI components (singletons) required by a client module.
22 // Type: Template method.
23 // Args: vErrorResrcId - (R) The string resource ID error message identifier to place in errMsg.
24 // vwrbOk - (RW) On input True = Try to initialize MI driver module.
25 // On output True = MI driver module initialise successfully.
26 // vwrErrMsg - (W) MI driver module initialise error description on failure.
27 // Return: MIstatus::success - Functional succeeded.
28 // MIstatus::failure - Functional failed.
32 ModuleInit(const MIint vErrorResrcId, bool &vwrbOk, CMIUtilString &vwrErrMsg)
34 if (vwrbOk && !T::Instance().Initialize())
36 vwrbOk = MIstatus::failure;
37 vwrErrMsg = CMIUtilString::Format(MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str());
43 //++ ============================================================================
44 // Details: Short cut helper function to simplify repeated shutdown of
45 // MI components (singletons) required by a client module.
46 // Type: Template method.
47 // Args: vErrorResrcId - (R) The string resource ID error message identifier
48 // to place in errMsg.
49 // vwrbOk - (W) If not already false make false on module
51 // vwrErrMsg - (RW) Append to existing error description string MI
52 // driver module initialise error description on
54 // Return: True - Module shutdown succeeded.
55 // False - Module shutdown failed.
59 ModuleShutdown(const MIint vErrorResrcId, bool &vwrbOk, CMIUtilString &vwrErrMsg)
61 bool bOk = MIstatus::success;
63 if (!T::Instance().Shutdown())
65 const bool bMoreThanOneError(!vwrErrMsg.empty());
66 bOk = MIstatus::failure;
67 if (bMoreThanOneError)
69 vwrErrMsg += CMIUtilString::Format(MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str());
72 vwrbOk = bOk ? vwrbOk : MIstatus::failure;