• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef SWING_SERVICE_WRAPPER_H
16 #define SWING_SERVICE_WRAPPER_H
17 
18 #include <string>
19 #include <mutex>
20 
21 #include "intell_voice_log.h"
22 
23 #define LOG_TAG "SwingServiceWrapper"
24 
25 namespace OHOS {
26 namespace IntellVoiceEngine {
27 #define LOAD_FUNCTION(funcPoint, funcPrototype, funcName, impl, errCount)          \
28     do {                                                                 \
29         (funcPoint) = (funcPrototype)dlsym((impl).handle, (funcName)); \
30         const char *strErr = dlerror();                                  \
31         if (strErr != nullptr) {                                         \
32             INTELL_VOICE_LOG_ERROR("load function failed: %{public}s", strErr);               \
33             (errCount)++;                                        \
34         }                                                                \
35     } while (0)
36 
37 using SubscribeSwingEventPtr = int (*)(const char *swingEventType, const char *eventParams);
38 using UnSubscribeSwingEventPtr = int (*)(const char *swingEventType, const char *eventParams);
39 
40 struct SwingServiceManagerPriv {
41     void *handle { nullptr };
42     SubscribeSwingEventPtr subscribeSwingEvent { nullptr };
43     UnSubscribeSwingEventPtr unSubscribeSwingEvent { nullptr };
44 };
45 
46 class SwingServiceWrapper {
47 public:
48     SwingServiceWrapper();
49     ~SwingServiceWrapper();
50 
GetInstance()51     static SwingServiceWrapper &GetInstance()
52     {
53         static SwingServiceWrapper swingServiceWrapper;
54         return swingServiceWrapper;
55     }
56 
57     int32_t SubscribeSwingEvent(std::string swingEventType, std::string eventParams);
58     int32_t UnSubscribeSwingEvent(std::string swingEventType, std::string eventParams);
59 
60 private:
61     int32_t LoadSwingServiceLib();
62     void UnloadSwingServiceLib();
63     int32_t LoadLibFunction();
64 
65 private:
66     std::mutex mutex_ {};
67     SwingServiceManagerPriv swingServicePriv_;
68 };
69 }
70 }
71 #undef LOG_TAG
72 #endif