Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 1 | //===-- 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 Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 9 | // |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 10 | // Copyright: None. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 11 | //-- |
| 12 | |
| 13 | #pragma once |
| 14 | |
| 15 | namespace MI |
| 16 | { |
| 17 | |
| 18 | // In house headers: |
| 19 | #include "MIUtilString.h" |
| 20 | #include "MICmnResources.h" |
| 21 | |
| 22 | //++ ============================================================================ |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 23 | // 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. |
| 27 | // vwrbOk - (RW) On input True = Try to initalise MI driver module. |
| 28 | // 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 Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 34 | //-- |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 35 | template <typename T> |
| 36 | bool |
| 37 | ModuleInit(const MIint vErrorResrcId, bool &vwrbOk, CMIUtilString &vwrErrMsg) |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 38 | { |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 39 | if (vwrbOk && !T::Instance().Initialize()) |
| 40 | { |
| 41 | vwrbOk = MIstatus::failure; |
| 42 | vwrErrMsg = CMIUtilString::Format(MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str()); |
| 43 | } |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 44 | |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 45 | return vwrbOk; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | //++ ============================================================================ |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 49 | // Details: Short cut helper function to simplify repeated shutodown of |
| 50 | // 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 Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 63 | //-- |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 64 | template <typename T> |
| 65 | bool |
| 66 | ModuleShutdown(const MIint vErrorResrcId, bool &vwrbOk, CMIUtilString &vwrErrMsg) |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 67 | { |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 68 | bool bOk = MIstatus::success; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 69 | |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 70 | 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 Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 78 | |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 79 | vwrbOk = bOk ? vwrbOk : MIstatus::failure; |
| 80 | |
| 81 | return bOk; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Ed Maste | 1adc731 | 2014-06-24 19:18:28 +0000 | [diff] [blame] | 84 | } // namespace MI |