blob: 831c60aecfefb6af9768b499ba2c0137663afa2a [file] [log] [blame]
Deepak Panickal6f9c4682014-05-16 10:51:01 +00001//===-- MIUtilSingletonHelper.h ---------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Deepak Panickal6f9c4682014-05-16 10:51:01 +00009
10#pragma once
11
Deepak Panickal6f9c4682014-05-16 10:51:01 +000012// In house headers:
Deepak Panickal6f9c4682014-05-16 10:51:01 +000013#include "MICmnResources.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000014#include "MIUtilString.h"
Deepak Panickal6f9c4682014-05-16 10:51:01 +000015
Raphael Isemann81cc1322018-05-26 14:39:35 +000016namespace MI {
17
Kate Stoneb9c1b512016-09-06 20:57:50 +000018//++
19//============================================================================
Zachary Turner1d6af022014-11-17 18:06:21 +000020// Details: Short cut helper function to simplify repeated initialisation of
21// MI components (singletons) required by a client module.
22// Type: Template method.
Kate Stoneb9c1b512016-09-06 20:57:50 +000023// 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
26// module.
27// On output True = MI driver module initialise
28// successfully.
29// vwrErrMsg - (W) MI driver module initialise error description
30// on failure.
Zachary Turner1d6af022014-11-17 18:06:21 +000031// Return: MIstatus::success - Functional succeeded.
32// MIstatus::failure - Functional failed.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000033//--
Zachary Turner1d6af022014-11-17 18:06:21 +000034template <typename T>
Kate Stoneb9c1b512016-09-06 20:57:50 +000035bool 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());
41 }
Deepak Panickal6f9c4682014-05-16 10:51:01 +000042
Kate Stoneb9c1b512016-09-06 20:57:50 +000043 return vwrbOk;
Deepak Panickal6f9c4682014-05-16 10:51:01 +000044}
45
Kate Stoneb9c1b512016-09-06 20:57:50 +000046//++
47//============================================================================
Bruce Mitchenerae4c0262015-07-07 14:04:40 +000048// Details: Short cut helper function to simplify repeated shutdown of
Zachary Turner1d6af022014-11-17 18:06:21 +000049// MI components (singletons) required by a client module.
50// Type: Template method.
Kate Stoneb9c1b512016-09-06 20:57:50 +000051// Args: vErrorResrcId - (R) The string resource ID error message
52// identifier
Zachary Turner1d6af022014-11-17 18:06:21 +000053// to place in errMsg.
54// vwrbOk - (W) If not already false make false on module
55// shutdown failure.
Kate Stoneb9c1b512016-09-06 20:57:50 +000056// vwrErrMsg - (RW) Append to existing error description string
57// MI
Zachary Turner1d6af022014-11-17 18:06:21 +000058// driver module initialise error description on
59// failure.
60// Return: True - Module shutdown succeeded.
61// False - Module shutdown failed.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000062//--
Zachary Turner1d6af022014-11-17 18:06:21 +000063template <typename T>
Kate Stoneb9c1b512016-09-06 20:57:50 +000064bool ModuleShutdown(const MIint vErrorResrcId, bool &vwrbOk,
65 CMIUtilString &vwrErrMsg) {
66 bool bOk = MIstatus::success;
Deepak Panickal6f9c4682014-05-16 10:51:01 +000067
Kate Stoneb9c1b512016-09-06 20:57:50 +000068 if (!T::Instance().Shutdown()) {
69 const bool bMoreThanOneError(!vwrErrMsg.empty());
70 bOk = MIstatus::failure;
71 if (bMoreThanOneError)
72 vwrErrMsg += ", ";
73 vwrErrMsg += CMIUtilString::Format(
74 MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str());
75 }
Deepak Panickal6f9c4682014-05-16 10:51:01 +000076
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 vwrbOk = bOk ? vwrbOk : MIstatus::failure;
Zachary Turner1d6af022014-11-17 18:06:21 +000078
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 return bOk;
Deepak Panickal6f9c4682014-05-16 10:51:01 +000080}
81
Ed Maste1adc7312014-06-24 19:18:28 +000082} // namespace MI