]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MIUtilSingletonHelper.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MIUtilSingletonHelper.h
1 //===-- MIUtilSingletonHelper.h ---------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 #pragma once
10
11 // In house headers:
12 #include "MICmnResources.h"
13 #include "MIUtilString.h"
14
15 namespace MI {
16
17 //++
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
25 //          module.
26 //                                 On output True = MI driver module initialise
27 //                                 successfully.
28 //          vwrErrMsg       - (W)  MI driver module initialise error description
29 //          on failure.
30 // Return:  MIstatus::success - Functional succeeded.
31 //          MIstatus::failure - Functional failed.
32 //--
33 template <typename T>
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());
40   }
41
42   return vwrbOk;
43 }
44
45 //++
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
51 // identifier
52 //                                 to place in errMsg.
53 //          vwrbOk          - (W)  If not already false make false on module
54 //                                 shutdown failure.
55 //          vwrErrMsg       - (RW) Append to existing error description string
56 //          MI
57 //                                 driver module initialise error description on
58 //                                 failure.
59 // Return:  True - Module shutdown succeeded.
60 //          False - Module shutdown failed.
61 //--
62 template <typename T>
63 bool ModuleShutdown(const MIint vErrorResrcId, bool &vwrbOk,
64                     CMIUtilString &vwrErrMsg) {
65   bool bOk = MIstatus::success;
66
67   if (!T::Instance().Shutdown()) {
68     const bool bMoreThanOneError(!vwrErrMsg.empty());
69     bOk = MIstatus::failure;
70     if (bMoreThanOneError)
71       vwrErrMsg += ", ";
72     vwrErrMsg += CMIUtilString::Format(
73         MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str());
74   }
75
76   vwrbOk = bOk ? vwrbOk : MIstatus::failure;
77
78   return bOk;
79 }
80
81 } // namespace MI