1 //===-- MIUtilSingletonHelper.h ---------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 #include "MICmnResources.h"
13 #include "MIUtilString.h"
18 //============================================================================
19 // Details: Short cut helper function to simplify repeated initialisation of
20 // MI components (singletons) required by a client module.
21 // Type: Template method.
22 // Args: vErrorResrcId - (R) The string resource ID error message
23 // identifier to place in errMsg.
24 // vwrbOk - (RW) On input True = Try to initialize MI driver
26 // On output True = MI driver module initialise
28 // vwrErrMsg - (W) MI driver module initialise error description
30 // Return: MIstatus::success - Functional succeeded.
31 // MIstatus::failure - Functional failed.
34 bool ModuleInit(const MIint vErrorResrcId, bool &vwrbOk,
35 CMIUtilString &vwrErrMsg) {
36 if (vwrbOk && !T::Instance().Initialize()) {
37 vwrbOk = MIstatus::failure;
38 vwrErrMsg = CMIUtilString::Format(
39 MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str());
46 //============================================================================
47 // Details: Short cut helper function to simplify repeated shutdown of
48 // MI components (singletons) required by a client module.
49 // Type: Template method.
50 // Args: vErrorResrcId - (R) The string resource ID error message
52 // to place in errMsg.
53 // vwrbOk - (W) If not already false make false on module
55 // vwrErrMsg - (RW) Append to existing error description string
57 // driver module initialise error description on
59 // Return: True - Module shutdown succeeded.
60 // False - Module shutdown failed.
63 bool ModuleShutdown(const MIint vErrorResrcId, bool &vwrbOk,
64 CMIUtilString &vwrErrMsg) {
65 bool bOk = MIstatus::success;
67 if (!T::Instance().Shutdown()) {
68 const bool bMoreThanOneError(!vwrErrMsg.empty());
69 bOk = MIstatus::failure;
70 if (bMoreThanOneError)
72 vwrErrMsg += CMIUtilString::Format(
73 MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str());
76 vwrbOk = bOk ? vwrbOk : MIstatus::failure;