blob: 19cc3a92e82f700d8dca6561353f1fb1e1f60861 [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//
Zachary Turner1d6af022014-11-17 18:06:21 +000010// Copyright: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000011//--
12
13#pragma once
14
15namespace MI
16{
17
18// In house headers:
19#include "MIUtilString.h"
20#include "MICmnResources.h"
21
22//++ ============================================================================
Zachary Turner1d6af022014-11-17 18:06:21 +000023// Details: Short cut helper function to simplify repeated initialisation of
24// MI components (singletons) required by a client module.
25// Type: Template method.
26// Args: vErrorResrcId - (R) The string resource ID error message identifier to place in errMsg.
Bruce Mitchenerae4c0262015-07-07 14:04:40 +000027// vwrbOk - (RW) On input True = Try to initialize MI driver module.
Zachary Turner1d6af022014-11-17 18:06:21 +000028// On output True = MI driver module initialise successfully.
29// vwrErrMsg - (W) MI driver module initialise error description on failure.
30// Return: MIstatus::success - Functional succeeded.
31// MIstatus::failure - Functional failed.
32// Authors: Aidan Dodds 17/03/2014.
33// Changes: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000034//--
Zachary Turner1d6af022014-11-17 18:06:21 +000035template <typename T>
36bool
37ModuleInit(const MIint vErrorResrcId, bool &vwrbOk, CMIUtilString &vwrErrMsg)
Deepak Panickal6f9c4682014-05-16 10:51:01 +000038{
Zachary Turner1d6af022014-11-17 18:06:21 +000039 if (vwrbOk && !T::Instance().Initialize())
40 {
41 vwrbOk = MIstatus::failure;
42 vwrErrMsg = CMIUtilString::Format(MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str());
43 }
Deepak Panickal6f9c4682014-05-16 10:51:01 +000044
Zachary Turner1d6af022014-11-17 18:06:21 +000045 return vwrbOk;
Deepak Panickal6f9c4682014-05-16 10:51:01 +000046}
47
48//++ ============================================================================
Bruce Mitchenerae4c0262015-07-07 14:04:40 +000049// Details: Short cut helper function to simplify repeated shutdown of
Zachary Turner1d6af022014-11-17 18:06:21 +000050// MI components (singletons) required by a client module.
51// Type: Template method.
52// Args: vErrorResrcId - (R) The string resource ID error message identifier
53// to place in errMsg.
54// vwrbOk - (W) If not already false make false on module
55// shutdown failure.
56// vwrErrMsg - (RW) Append to existing error description string MI
57// driver module initialise error description on
58// failure.
59// Return: True - Module shutdown succeeded.
60// False - Module shutdown failed.
61// Authors: Aidan Dodds 17/03/2014.
62// Changes: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000063//--
Zachary Turner1d6af022014-11-17 18:06:21 +000064template <typename T>
65bool
66ModuleShutdown(const MIint vErrorResrcId, bool &vwrbOk, CMIUtilString &vwrErrMsg)
Deepak Panickal6f9c4682014-05-16 10:51:01 +000067{
Zachary Turner1d6af022014-11-17 18:06:21 +000068 bool bOk = MIstatus::success;
Deepak Panickal6f9c4682014-05-16 10:51:01 +000069
Zachary Turner1d6af022014-11-17 18:06:21 +000070 if (!T::Instance().Shutdown())
71 {
72 const bool bMoreThanOneError(!vwrErrMsg.empty());
73 bOk = MIstatus::failure;
74 if (bMoreThanOneError)
75 vwrErrMsg += ", ";
76 vwrErrMsg += CMIUtilString::Format(MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str());
77 }
Deepak Panickal6f9c4682014-05-16 10:51:01 +000078
Zachary Turner1d6af022014-11-17 18:06:21 +000079 vwrbOk = bOk ? vwrbOk : MIstatus::failure;
80
81 return bOk;
Deepak Panickal6f9c4682014-05-16 10:51:01 +000082}
83
Ed Maste1adc7312014-06-24 19:18:28 +000084} // namespace MI