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 | |
| 10 | #pragma once |
| 11 | |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 12 | // In house headers: |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 13 | #include "MICmnResources.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 14 | #include "MIUtilString.h" |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 15 | |
Raphael Isemann | 81cc132 | 2018-05-26 14:39:35 +0000 | [diff] [blame] | 16 | namespace MI { |
| 17 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 18 | //++ |
| 19 | //============================================================================ |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 20 | // Details: Short cut helper function to simplify repeated initialisation of |
| 21 | // MI components (singletons) required by a client module. |
| 22 | // Type: Template method. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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 |
| 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 Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 31 | // Return: MIstatus::success - Functional succeeded. |
| 32 | // MIstatus::failure - Functional failed. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 33 | //-- |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 34 | template <typename T> |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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()); |
| 41 | } |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 42 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 43 | return vwrbOk; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 46 | //++ |
| 47 | //============================================================================ |
Bruce Mitchener | ae4c026 | 2015-07-07 14:04:40 +0000 | [diff] [blame] | 48 | // Details: Short cut helper function to simplify repeated shutdown of |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 49 | // MI components (singletons) required by a client module. |
| 50 | // Type: Template method. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | // Args: vErrorResrcId - (R) The string resource ID error message |
| 52 | // identifier |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 53 | // to place in errMsg. |
| 54 | // vwrbOk - (W) If not already false make false on module |
| 55 | // shutdown failure. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | // vwrErrMsg - (RW) Append to existing error description string |
| 57 | // MI |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 58 | // driver module initialise error description on |
| 59 | // failure. |
| 60 | // Return: True - Module shutdown succeeded. |
| 61 | // False - Module shutdown failed. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 62 | //-- |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 63 | template <typename T> |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | bool ModuleShutdown(const MIint vErrorResrcId, bool &vwrbOk, |
| 65 | CMIUtilString &vwrErrMsg) { |
| 66 | bool bOk = MIstatus::success; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 67 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 68 | 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 Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 76 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | vwrbOk = bOk ? vwrbOk : MIstatus::failure; |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 78 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 79 | return bOk; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Ed Maste | 1adc731 | 2014-06-24 19:18:28 +0000 | [diff] [blame] | 82 | } // namespace MI |