Signed-off-by: PipiSummer <xiatian44@huawei.com>
Change-Id: Ia4788841fd5d694197b85af4a3a6549a5bd8db6b
This commit is contained in:
zhaoshenghua 2024-07-31 11:34:49 +08:00 committed by PipiSummer
parent 99674f4eb4
commit 2039092ff3
6 changed files with 51 additions and 62 deletions

View File

@ -19,11 +19,11 @@
#include "input_method_ffi_structs.h"
extern "C" {
FFI_EXPORT int32_t CJ_GetDefaultInputMethod(CInputMethodProperty* props);
FFI_EXPORT int32_t CJ_GetCurrentInputMethod(CInputMethodProperty* props);
FFI_EXPORT int32_t CJ_GetDefaultInputMethod(CInputMethodProperty &props);
FFI_EXPORT int32_t CJ_GetCurrentInputMethod(CInputMethodProperty &props);
FFI_EXPORT int32_t CJ_SwitchInputMethod(bool &result, CInputMethodProperty props);
FFI_EXPORT int32_t CJ_SwitchCurrentInputMethodSubtype(bool &result, CInputMethodSubtype target);
FFI_EXPORT int32_t CJ_GetCurrentInputMethodSubtype(CInputMethodSubtype* props);
FFI_EXPORT int32_t CJ_GetCurrentInputMethodSubtype(CInputMethodSubtype &props);
FFI_EXPORT int32_t CJ_SwitchCurrentInputMethodAndSubtype(bool &result, CInputMethodProperty target, CInputMethodSubtype subtype);
FFI_EXPORT RetInputMethodSubtype CJ_ListInputMethodSubtype(CInputMethodProperty props);
FFI_EXPORT RetInputMethodSubtype CJ_ListCurrentInputMethodSubtype();
@ -32,6 +32,8 @@ extern "C" {
FFI_EXPORT int32_t CJ_InputMethodSettingOn(uint32_t type, void (*func)(CInputMethodProperty, CInputMethodSubtype));
FFI_EXPORT int32_t CJ_InputMethodSettingOff(uint32_t type);
FFI_EXPORT int32_t CJ_ShowOptionalInputMethods(bool& result);
FFI_EXPORT int32_t CJ_InputMethodCOntrollerOn(char* type, int64_t id);
FFI_EXPORT int32_t CJ_InputMethodCOntrollerOff(char* type);
}
#endif // INPUT_METHOD_FFI_H

View File

@ -32,12 +32,9 @@ namespace OHOS::MiscServices {
void OnImeChange(const Property &property, const SubProperty &subProperty) override;
private:
static std::mutex eventHandlerMutex_;
static std::shared_ptr<AppExecFwk::EventHandler> handler_;
static std::mutex msMutex_;
static std::shared_ptr<CJGetInputMethodSetting> inputMethod_;
std::function<void(CInputMethodProperty, CInputMethodSubtype)> callback = nullptr;
static std::shared_ptr<AppExecFwk::EventHandler> GetEventHandler();
};
}

View File

@ -27,9 +27,9 @@ namespace OHOS::MiscServices {
class FFI_EXPORT Utils {
public:
static char* MallocCString(const std::string &origin);
static void InputMethodProperty2C(CInputMethodProperty *props, const Property &property);
static void InputMethodProperty2C(CInputMethodProperty &props, const Property &property);
static Property C2InputMethodProperty(CInputMethodProperty props);
static void InputMethodSubProperty2C(CInputMethodSubtype *props, const SubProperty &property);
static void InputMethodSubProperty2C(CInputMethodSubtype &props, const SubProperty &property);
};
}
#endif

View File

@ -26,7 +26,7 @@ namespace OHOS::MiscServices
{
extern "C"
{
int32_t CJ_GetDefaultInputMethod(CInputMethodProperty *props)
int32_t CJ_GetDefaultInputMethod(CInputMethodProperty &props)
{
std::shared_ptr<Property> property;
int32_t ret = InputMethodController::GetInstance()->GetDefaultInputMethod(property);
@ -39,7 +39,7 @@ namespace OHOS::MiscServices
return ret;
}
int32_t CJ_GetCurrentInputMethod(CInputMethodProperty *props)
int32_t CJ_GetCurrentInputMethod(CInputMethodProperty &props)
{
std::shared_ptr<Property> property = InputMethodController::GetInstance()->GetCurrentInputMethod();
if (property == nullptr)
@ -74,7 +74,7 @@ namespace OHOS::MiscServices
return errCode;
}
int32_t CJ_GetCurrentInputMethodSubtype(CInputMethodSubtype *props)
int32_t CJ_GetCurrentInputMethodSubtype(CInputMethodSubtype &props)
{
std::shared_ptr<SubProperty> subProperty = InputMethodController::GetInstance()->GetCurrentInputMethodSubtype();
if (subProperty == nullptr) {
@ -111,7 +111,7 @@ namespace OHOS::MiscServices
IMSA_HILOGI("exec ListInputMethodSubtype success");
ret.size = subProps.size();
if (ret.size > 0) {
ret.head = static_cast<CInputMethodSubtype *>(malloc(sizeof(CInputMethodSubtype*) * ret.size));
ret.head = static_cast<CInputMethodSubtype *>(malloc(sizeof(CInputMethodSubtype) * ret.size));
}
if (ret.head == nullptr) {
ret.size = 0;
@ -119,7 +119,7 @@ namespace OHOS::MiscServices
}
for (unsigned int i = 0; i < ret.size; i++) {
CInputMethodSubtype props;
Utils::InputMethodSubProperty2C(&props, subProps[i]);
Utils::InputMethodSubProperty2C(props, subProps[i]);
ret.head[i] = props;
}
return ret;
@ -138,7 +138,7 @@ namespace OHOS::MiscServices
IMSA_HILOGI("exec ListCurrentInputMethodSubtype success.");
ret.size = subProps.size();
if (ret.size > 0) {
ret.head = static_cast<CInputMethodSubtype *>(malloc(sizeof(CInputMethodSubtype*) * ret.size));
ret.head = static_cast<CInputMethodSubtype *>(malloc(sizeof(CInputMethodSubtype) * ret.size));
}
if (ret.head == nullptr) {
ret.size = 0;
@ -146,7 +146,7 @@ namespace OHOS::MiscServices
}
for (unsigned int i = 0; i < ret.size; i++) {
CInputMethodSubtype props;
Utils::InputMethodSubProperty2C(&props, subProps[i]);
Utils::InputMethodSubProperty2C(props, subProps[i]);
ret.head[i] = props;
}
return ret;
@ -164,7 +164,7 @@ namespace OHOS::MiscServices
}
ret.size = properties.size();
if (ret.size > 0) {
ret.head = static_cast<CInputMethodProperty *>(malloc(sizeof(CInputMethodProperty*) * ret.size));
ret.head = static_cast<CInputMethodProperty *>(malloc(sizeof(CInputMethodProperty) * ret.size));
}
if (ret.head == nullptr) {
ret.size = 0;
@ -172,7 +172,7 @@ namespace OHOS::MiscServices
}
for (unsigned int i = 0; i < ret.size; i++) {
CInputMethodProperty props;
Utils::InputMethodProperty2C(&props, properties[i]);
Utils::InputMethodProperty2C(props, properties[i]);
ret.head[i] = props;
}
return ret;
@ -190,7 +190,7 @@ namespace OHOS::MiscServices
}
ret.size = properties.size();
if (ret.size > 0) {
ret.head = static_cast<CInputMethodProperty *>(malloc(sizeof(CInputMethodProperty*) * ret.size));
ret.head = static_cast<CInputMethodProperty *>(malloc(sizeof(CInputMethodProperty) * ret.size));
}
if (ret.head == nullptr) {
ret.size = 0;
@ -198,7 +198,7 @@ namespace OHOS::MiscServices
}
for (unsigned int i = 0; i < ret.size; i++) {
CInputMethodProperty props;
Utils::InputMethodProperty2C(&props, properties[i]);
Utils::InputMethodProperty2C(props, properties[i]);
ret.head[i] = props;
}
return ret;
@ -224,5 +224,15 @@ namespace OHOS::MiscServices
}
return errCode;
}
int32_t CJ_InputMethodCOntrollerOn(char* type, int64_t id)
{
return 0;
}
int32_t CJ_InputMethodCOntrollerOff(char* type)
{
return 0;
}
}
}

View File

@ -22,8 +22,6 @@
namespace OHOS::MiscServices {
std::mutex CJGetInputMethodSetting::msMutex_;
std::shared_ptr<AppExecFwk::EventHandler> CJGetInputMethodSetting::handler_{ nullptr };
std::mutex CJGetInputMethodSetting::eventHandlerMutex_;
std::shared_ptr<CJGetInputMethodSetting> CJGetInputMethodSetting::inputMethod_{ nullptr };
std::shared_ptr<CJGetInputMethodSetting> CJGetInputMethodSetting::GetIMSInstance()
@ -70,29 +68,11 @@ int32_t CJGetInputMethodSetting::UnSubscribe(uint32_t type)
void CJGetInputMethodSetting::OnImeChange(const Property &property, const SubProperty &subProperty)
{
std::string type = "imeChange";
auto eventHandler = CJGetInputMethodSetting::GetEventHandler();
if (eventHandler == nullptr) {
IMSA_HILOGE("eventHandler is nullptr!");
return;
}
IMSA_HILOGI("start");
auto task = [property, subProperty, this]() {
CInputMethodProperty prop;
CInputMethodSubtype subProp;
Utils::InputMethodSubProperty2C(&subProp, subProperty);
Utils::InputMethodProperty2C(&prop, property);
callback(prop, subProp);
};
eventHandler->PostTask(task, type);
}
std::shared_ptr<AppExecFwk::EventHandler> CJGetInputMethodSetting::GetEventHandler()
{
if (handler_ == nullptr) {
std::lock_guard<std::mutex> lock(eventHandlerMutex_);
handler_ = AppExecFwk::EventHandler::Current();
}
std::lock_guard<std::mutex> lock(eventHandlerMutex_);
return handler_;
IMSA_HILOGD("start");
CInputMethodProperty prop;
CInputMethodSubtype subProp;
Utils::InputMethodSubProperty2C(subProp, subProperty);
Utils::InputMethodProperty2C(prop, property);
callback(prop, subProp);
}
}

View File

@ -30,14 +30,14 @@ char* Utils::MallocCString(const std::string &origin)
return std::char_traits<char>::copy(res, origin.c_str(), len);
}
void Utils::InputMethodProperty2C(CInputMethodProperty *props, const Property &property)
void Utils::InputMethodProperty2C(CInputMethodProperty &props, const Property &property)
{
props->name = Utils::MallocCString(property.name);
props->id = Utils::MallocCString(property.id);
props->label = Utils::MallocCString(property.label);
props->labelId = property.labelId;
props->icon = Utils::MallocCString(property.icon);
props->iconId = property.iconId;
props.name = Utils::MallocCString(property.name);
props.id = Utils::MallocCString(property.id);
props.label = Utils::MallocCString(property.label);
props.labelId = property.labelId;
props.icon = Utils::MallocCString(property.icon);
props.iconId = property.iconId;
}
Property Utils::C2InputMethodProperty(CInputMethodProperty props)
@ -52,16 +52,16 @@ Property Utils::C2InputMethodProperty(CInputMethodProperty props)
return property;
}
void Utils::InputMethodSubProperty2C(CInputMethodSubtype *props, const SubProperty &property)
void Utils::InputMethodSubProperty2C(CInputMethodSubtype &props, const SubProperty &property)
{
props->name = Utils::MallocCString(property.name);
props->id = Utils::MallocCString(property.id);
props->label = Utils::MallocCString(property.label);
props->labelId = property.labelId;
props->icon = Utils::MallocCString(property.icon);
props->iconId = property.iconId;
props->mode = Utils::MallocCString(property.mode);
props->locale = Utils::MallocCString(property.locale);
props->language = Utils::MallocCString(property.language);
props.name = Utils::MallocCString(property.name);
props.id = Utils::MallocCString(property.id);
props.label = Utils::MallocCString(property.label);
props.labelId = property.labelId;
props.icon = Utils::MallocCString(property.icon);
props.iconId = property.iconId;
props.mode = Utils::MallocCString(property.mode);
props.locale = Utils::MallocCString(property.locale);
props.language = Utils::MallocCString(property.language);
}
}