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 //===----------------------------------------------------------------------===//
15 #include "MICmnResources.h"
16 #include "MIUtilString.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
24 // identifier to place in errMsg.
25 // vwrbOk - (RW) On input True = Try to initialize MI driver
27 // On output True = MI driver module initialise
29 // vwrErrMsg - (W) MI driver module initialise error description
31 // Return: MIstatus::success - Functional succeeded.
32 // MIstatus::failure - Functional failed.
35 bool ModuleInit(const MIint vErrorResrcId, bool &vwrbOk,
36 CMIUtilString &vwrErrMsg) {
37 if (vwrbOk && !T::Instance().Initialize()) {
38 vwrbOk = MIstatus::failure;
39 vwrErrMsg = CMIUtilString::Format(
40 MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str());
47 //============================================================================
48 // Details: Short cut helper function to simplify repeated shutdown of
49 // MI components (singletons) required by a client module.
50 // Type: Template method.
51 // Args: vErrorResrcId - (R) The string resource ID error message
53 // to place in errMsg.
54 // vwrbOk - (W) If not already false make false on module
56 // vwrErrMsg - (RW) Append to existing error description string
58 // driver module initialise error description on
60 // Return: True - Module shutdown succeeded.
61 // False - Module shutdown failed.
64 bool ModuleShutdown(const MIint vErrorResrcId, bool &vwrbOk,
65 CMIUtilString &vwrErrMsg) {
66 bool bOk = MIstatus::success;
68 if (!T::Instance().Shutdown()) {
69 const bool bMoreThanOneError(!vwrErrMsg.empty());
70 bOk = MIstatus::failure;
71 if (bMoreThanOneError)
73 vwrErrMsg += CMIUtilString::Format(
74 MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str());
77 vwrbOk = bOk ? vwrbOk : MIstatus::failure;