1 /* 2 * Copyright (c) 2024 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 IMF_MESSAGE_HANDLER_INFO 17 #define IMF_MESSAGE_HANDLER_INFO 18 19 #include "async_call.h" 20 #include "global.h" 21 #include "input_method_utils.h" 22 #include "js_utils.h" 23 24 namespace OHOS { 25 namespace MiscServices { 26 struct MessageHandlerInfo { 27 std::chrono::system_clock::time_point timestamp{}; 28 ArrayBuffer arrayBuffer; 29 bool operator==(const MessageHandlerInfo &info) const 30 { 31 return (timestamp == info.timestamp && arrayBuffer == info.arrayBuffer); 32 } 33 }; 34 35 struct SendMessageContext : public AsyncCall::Context { 36 ArrayBuffer arrayBuffer; 37 napi_status status = napi_generic_failure; 38 MessageHandlerInfo info; SendMessageContextSendMessageContext39 SendMessageContext() : Context(nullptr, nullptr){}; SendMessageContextSendMessageContext40 SendMessageContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)){}; 41 operatorSendMessageContext42 napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override 43 { 44 CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg); 45 return Context::operator()(env, argc, argv, self); 46 } operatorSendMessageContext47 napi_status operator()(napi_env env, napi_value *result) override 48 { 49 if (status_ != napi_ok) { 50 output_ = nullptr; 51 return status_; 52 } 53 return Context::operator()(env, result); 54 } 55 }; 56 } // namespace MiscServices 57 } // namespace OHOS 58 #endif // IMF_MESSAGE_HANDLER_INFO