• 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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_CONTAINER_HANDLER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_CONTAINER_HANDLER_H
18 
19 #include <map>
20 #include <sstream>
21 #include <unordered_map>
22 
23 #include "base/memory/ace_type.h"
24 
25 namespace OHOS::Ace {
26 struct HandlerData {
27 public:
28     int32_t actionCode = -1;
29     std::map<std::string, std::string> params;
30 };
31 
32 struct HandlerReply {
33 public:
34     std::map<std::string, std::string> replyParams;
35 
36     template<typename T>
GetParamHandlerReply37     T GetParam(const std::string& matchString, const T& defaultValue)
38     {
39         auto it = replyParams.find(matchString);
40         if (it != replyParams.end()) {
41             std::istringstream iss(it->second);
42             T value;
43             if (iss >> value) {
44                 return value;
45             } else {
46                 return defaultValue;
47             }
48         }
49         return defaultValue;
50     }
51 
52     template<typename T>
SetParamHandlerReply53     void SetParam(const std::string& keyString, const T& value)
54     {
55         std::ostringstream oss;
56         oss << value;
57         replyParams.emplace(keyString, oss.str());
58     }
59 };
60 
61 struct HostConfig {
62     bool isReportFrameEvent = false;
63 };
64 
65 class ContainerHandler : public virtual AceType {
66     DECLARE_ACE_TYPE(ContainerHandler, AceType);
67 
68 public:
69     ContainerHandler() = default;
70     ~ContainerHandler() override = default;
71 
SendDataToHost(const HandlerData & data,HandlerReply & reply)72     bool SendDataToHost(const HandlerData& data, HandlerReply& reply)
73     {
74         return OnReciveData(data, reply);
75     }
76 
OnReciveData(const HandlerData & data,HandlerReply & reply)77     virtual bool OnReciveData(const HandlerData& data, HandlerReply& reply) { return false; }
78 
GetHostConfig()79     const HostConfig& GetHostConfig() const
80     {
81         return hostConfig_;
82     }
83 
GetHostFocusWindowSceneCloseKeyboard(const std::function<void (bool)> & getKeyCallback)84     virtual void GetHostFocusWindowSceneCloseKeyboard(const std::function<void(bool)>& getKeyCallback) {};
85 
86 protected:
87     HostConfig hostConfig_;
88 };
89 
90 } // namespace OHOS::Ace
91 
92 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_CONTAINER_HANDLER_H
93