diff --git a/inputmethod/BUILD.gn b/inputmethod/BUILD.gn index cc1480cdb87beca13fa1874a4530dd6e8ab67a50..ef0543708dd53bc92f05fcad29c17be96c7b8790 100644 --- a/inputmethod/BUILD.gn +++ b/inputmethod/BUILD.gn @@ -24,6 +24,7 @@ ohos_ndk_library("libohinputmethod") { "./inputmethod/inputmethod_attach_options_capi.h", "./inputmethod/inputmethod_cursor_info_capi.h", "./inputmethod/inputmethod_inputmethod_proxy_capi.h", + "./inputmethod/inputmethod_message_handler_proxy_capi.h", "./inputmethod/inputmethod_private_command_capi.h", "./inputmethod/inputmethod_text_avoid_info_capi.h", "./inputmethod/inputmethod_text_config_capi.h", @@ -39,6 +40,7 @@ ohos_ndk_headers("libohinputmethod_header") { "./include/inputmethod_controller_capi.h", "./include/inputmethod_cursor_info_capi.h", "./include/inputmethod_inputmethod_proxy_capi.h", + "./include/inputmethod_message_handler_proxy_capi.h", "./include/inputmethod_private_command_capi.h", "./include/inputmethod_text_avoid_info_capi.h", "./include/inputmethod_text_config_capi.h", diff --git a/inputmethod/include/inputmethod_inputmethod_proxy_capi.h b/inputmethod/include/inputmethod_inputmethod_proxy_capi.h index f8257c2b6307f7237a2f11f46b4fbf05e44057b9..3d6dd29b1618ac41371651b20268df64d57a7c3a 100644 --- a/inputmethod/include/inputmethod_inputmethod_proxy_capi.h +++ b/inputmethod/include/inputmethod_inputmethod_proxy_capi.h @@ -39,6 +39,7 @@ #include "inputmethod_types_capi.h" #include "inputmethod_cursor_info_capi.h" #include "inputmethod_private_command_capi.h" +#include "inputmethod_message_handler_proxy_capi.h" #ifdef __cplusplus extern "C"{ #endif /* __cplusplus */ @@ -166,6 +167,48 @@ InputMethod_ErrorCode OH_InputMethodProxy_NotifyCursorUpdate( */ InputMethod_ErrorCode OH_InputMethodProxy_SendPrivateCommand( InputMethod_InputMethodProxy *inputMethodProxy, InputMethod_PrivateCommand *privateCommand[], size_t size); + +/** + * @brief Send customize message. + * + * @param inputMethodProxy Represents a pointer to an {@link OH_InputMethod_InputMethodProxy} instance. + * The inputMethodProxy is obtained from {@link OH_InputMethodController_Attach}. + * @param msgId The message id. Max size 256B. + * @param msgIdLength The size of message id. Max is 256B. + * @param msgParam The message param. Max size 128KB. + * @param msgParamLength The size of message param. Max is 128KB. + * @return Returns a specific error code. + * {@link IME_ERR_OK} - success. + * {@link IME_ERR_PARAMCHECK} - parameter check failed. + * {@link IME_ERR_IMCLIENT} - input method client error. + * {@link IME_ERR_DETACHED} - input method client detached. + * {@link IME_ERR_NULL_POINTER} - unexpected null pointer. + * {@link IME_ERR_REQUEST_NOT_ACCEPT} - another side was not register. + * {@link IME_ERR_BASIC_MODE} - ime security mode is basic mode. + * {@link IME_ERR_EDITABLE} - current is not editable status. + * Specific error codes can be referenced {@link InputMethod_ErrorCode}. + * @since 16 + */ +InputMethod_ErrorCode OH_InputMethodProxy_SendMessage(InputMethod_InputMethodProxy *inputMethodProxy, + const char16_t *msgId, size_t msgIdLength, const uint8_t *msgParam, size_t msgParamLength); + +/** + * @brief Register message handler. + * + * @param inputMethodProxy Represents a pointer to an {@link OH_InputMethod_InputMethodProxy} instance. + * The inputMethodProxy is obtained from {@link OH_InputMethodController_Attach}. + * @param messageHandler Represents a pointer to an {@link InputMethod_MessageHandlerProxy} instance. + * The caller needs to manage the lifecycle of messageHandler. + * @return Returns a specific error code. + * {@link IME_ERR_OK} - success. + * {@link IME_ERR_PARAMCHECK} - parameter check failed. + * {@link IME_ERR_DETACHED} - input method client detached. + * {@link IME_ERR_NULL_POINTER} - unexpected null pointer. + * Specific error codes can be referenced {@link InputMethod_ErrorCode}. + * @since 16 + */ +InputMethod_ErrorCode OH_InputMethodProxy_RecvMessage( + InputMethod_InputMethodProxy *inputMethodProxy, InputMethod_MessageHandlerProxy *messageHandler); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/inputmethod/include/inputmethod_message_handler_proxy_capi.h b/inputmethod/include/inputmethod_message_handler_proxy_capi.h new file mode 100644 index 0000000000000000000000000000000000000000..65c60e46dbb3ed53670325dbd37f15105893f007 --- /dev/null +++ b/inputmethod/include/inputmethod_message_handler_proxy_capi.h @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_INPUTMETHOD_MESSAGE_HANDLER_PROXY_CAPI_H +#define OHOS_INPUTMETHOD_MESSAGE_HANDLER_PROXY_CAPI_H +/** + * @addtogroup InputMethod + * @{ + * + * @brief InputMethod provides functions to use input methods and develop input methods. + * + * @since 16 + */ + +/** + * @file inputmethod_message_handler_proxy_capi.h + * + * @brief Provides functions for sending and receiving customize message from input method. + * + * @library libohinputmethod.so + * @kit IMEKit + * @syscap SystemCapability.MiscServices.InputMethodFramework + * @since 16 + * @version 1.0 + */ +#include + +#include "inputmethod_text_config_capi.h" +#include "inputmethod_types_capi.h" +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +/** + * @brief Define the InputMethod_MessageHandlerProxy structure type. + * + * Provides methods for sending and receiving customize message.\n + * When input method sends customize message or unregister message handler, the methods will be called.\n + * + * @since 16 + */ +typedef struct InputMethod_MessageHandlerProxy InputMethod_MessageHandlerProxy; + +/** + * @brief Called when unregister messager handler. + * + * You need to implement this function, set it to {@link InputMethod_MessageHandlerProxy} through {@link + * OH_MessageHandlerProxy_SetOnTerminatedFunc}, and use {@link OH_InputMethodProxy_RecvMessage} to complete the + * registration.\n + * + * @param messageHandlerProxy Represents a pointer to an + * {@link InputMethod_MessageHandlerProxy} instance which will be set in. + * @return Returns the result of handling private command. + * @since 16 + */ +typedef int32_t (*OH_MessageHandlerProxy_OnTerminatedFunc)(InputMethod_MessageHandlerProxy *messageHandlerProxy); + +/** + * @brief Called when receiving customize message from input method. + * + * You need to implement this function, set it to {@link InputMethod_MessageHandlerProxy} through {@link + * OH_MessageHandlerProxy_SetOnTerminatedFunc}, and use {@link OH_InputMethodProxy_RecvMessage} to complete the + * registration.\n + * + * @param messageHandlerProxy Represents a pointer to an + * {@link InputMethod_MessageHandlerProxy} instance which will be set in. + * @param msgId ArrayBuffer.msgId from input method. + * @param msgIdLength Size of ArrayBuffer.msgId. + * @param msgParam ArrayBuffer.msgParam from input method. + * @param msgParamLength Size of ArrayBuffer.msgParam. + * @since 16 + */ +typedef int32_t (*OH_MessageHandlerProxy_OnMessageFunc)(InputMethod_MessageHandlerProxy *messageHandlerProxy, + const char16_t msgId[], size_t msgIdLength, const uint8_t *msgParam, size_t msgParamLength); + +/** + * @brief Create a new {@link InputMethod_MessageHandlerProxy} instance. + * + * @return If the creation succeeds, a pointer to the newly created {@link InputMethod_MessageHandlerProxy} + * instance is returned. If the creation fails, NULL is returned, possible cause is insufficient memory. + * @since 16 + */ +InputMethod_MessageHandlerProxy *OH_MessageHandlerProxy_Create(void); + +/** + * @brief Destroy a {@link InputMethod_MessageHandlerProxy} instance. + * + * @param proxy The {@link InputMethod_MessageHandlerProxy} instance to be destroyed. + * @since 16 + */ +void OH_MessageHandlerProxy_Destroy(InputMethod_MessageHandlerProxy *proxy); + +/** + * @brief Set function {@link OH_MessageHandlerProxy_OnTerminatedFunc} into {@link InputMethod_MessageHandlerProxy}. + * + * @param proxy Represents a pointer to an + * {@link InputMethod_MessageHandlerProxy} instance which will be set function in. + * @param onTerminatedFunc Represents function {@link OH_MessageHandlerProxy_SetOnTerminatedFunc} which + * will be set. + * @return Returns a specific error code. + * {@link IME_ERR_OK} - success. + * {@link IME_ERR_NULL_POINTER} - unexpected null pointer. + * Specific error codes can be referenced {@link InputMethod_ErrorCode}. + * @since 16 + */ +InputMethod_ErrorCode OH_MessageHandlerProxy_SetOnTerminatedFunc( + InputMethod_MessageHandlerProxy *proxy, OH_MessageHandlerProxy_OnTerminatedFunc onTerminatedFunc); + +/** + * @brief Get function {@link OH_MessageHandlerProxy_OnTerminatedFunc} from {@link InputMethod_MessageHandlerProxy}. + * + * @param proxy Represents a pointer to an + * {@link InputMethod_MessageHandlerProxy} instance which will be get function from. + * @param onTerminatedFunc Represents function {@link OH_MessageHandlerProxy_GetOnTerminatedFunc} which + * will be get. + * @return Returns a specific error code. + * {@link IME_ERR_OK} - success. + * {@link IME_ERR_NULL_POINTER} - unexpected null pointer. + * Specific error codes can be referenced {@link InputMethod_ErrorCode}. + * @since 16 + */ +InputMethod_ErrorCode OH_MessageHandlerProxy_GetOnTerminatedFunc( + InputMethod_MessageHandlerProxy *proxy, OH_MessageHandlerProxy_OnTerminatedFunc *onTerminatedFunc); + +/** + * @brief Set function {@link OH_MessageHandlerProxy_OnMessageFunc} into {@link InputMethod_MessageHandlerProxy}. + * + * @param proxy Represents a pointer to an + * {@link InputMethod_MessageHandlerProxy} instance which will be set function in. + * @param onMessageFunc Represents function {@link OH_MessageHandlerProxy_SetOnMessageFunc} which + * will be set. + * @return Returns a specific error code. + * {@link IME_ERR_OK} - success. + * {@link IME_ERR_NULL_POINTER} - unexpected null pointer. + * Specific error codes can be referenced {@link InputMethod_ErrorCode}. + * @since 16 + */ +InputMethod_ErrorCode OH_MessageHandlerProxy_SetOnMessageFunc( + InputMethod_MessageHandlerProxy *proxy, OH_MessageHandlerProxy_OnMessageFunc onMessageFunc); + +/** + * @brief Get function {@link OH_MessageHandlerProxy_OnMessageFunc} from {@link InputMethod_MessageHandlerProxy}. + * + * @param proxy Represents a pointer to an {@link InputMethod_MessageHandlerProxy} instance which will be get function + * from. + * @param onMessageFunc Represents function {@link OH_MessageHandlerProxy_GetOnMessageFunc} which + * will be get. + * @return Returns a specific error code. + * {@link IME_ERR_OK} - success. + * {@link IME_ERR_NULL_POINTER} - unexpected null pointer. + * Specific error codes can be referenced {@link InputMethod_ErrorCode}. + * @since 16 + */ +InputMethod_ErrorCode OH_MessageHandlerProxy_GetOnMessageFunc( + InputMethod_MessageHandlerProxy *proxy, OH_MessageHandlerProxy_OnMessageFunc *onMessageFunc); +#ifdef __cplusplus +} +#endif /* __cplusplus */ +/** @} */ +#endif // OHOS_INPUTMETHOD_MESSAGE_HANDLER_PROXY_CAPI_H \ No newline at end of file diff --git a/inputmethod/include/inputmethod_types_capi.h b/inputmethod/include/inputmethod_types_capi.h index 0fc88c45514054cb20d41bcc77506692d228bc60..1c1ba5c1b831577514ea45f3185bd0b4b06c3c3d 100644 --- a/inputmethod/include/inputmethod_types_capi.h +++ b/inputmethod/include/inputmethod_types_capi.h @@ -251,7 +251,6 @@ typedef enum InputMethod_ErrorCode { * @error The error code in the correct case. */ IME_ERR_OK = 0, - /** * @error The error code when error is undefined. */ @@ -292,6 +291,21 @@ typedef enum InputMethod_ErrorCode { * @error The error code when input method client detached. */ IME_ERR_DETACHED = 12800009, + /** + * @error The error code when current security mode is basic mode. + * @since 16 + */ + IME_ERR_BASIC_MODE = 12800014, + /** + * @error The error code when another size was not register message handler. + * @since 16 + */ + IME_ERR_REQUEST_NOT_ACCEPT = 12800015, + /** + * @error The error code when current is not editable status. + * @since 16 + */ + IME_ERR_EDITABLE = 12800016, /** * @error The error code when unexpected null pointer. */