Release on full language support.
This commit is contained in:
86
hiknoengine/CMakeLists.txt
Normal file
86
hiknoengine/CMakeLists.txt
Normal file
@@ -0,0 +1,86 @@
|
||||
#
|
||||
# Copyright 2009-2017 Alibaba Cloud All rights reserved.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
set(public_header_dir ${CMAKE_CURRENT_SOURCE_DIR}/../include)
|
||||
|
||||
set(hiknoengine_public_header
|
||||
include/alibabacloud/hiknoengine/HiknoengineClient.h
|
||||
include/alibabacloud/hiknoengine/HiknoengineExport.h )
|
||||
|
||||
set(hiknoengine_public_header_model
|
||||
include/alibabacloud/hiknoengine/model/TranslateTextRequest.h
|
||||
include/alibabacloud/hiknoengine/model/TranslateTextResult.h )
|
||||
|
||||
set(hiknoengine_src
|
||||
src/HiknoengineClient.cc
|
||||
src/model/TranslateTextRequest.cc
|
||||
src/model/TranslateTextResult.cc )
|
||||
|
||||
add_library(hiknoengine ${LIB_TYPE}
|
||||
${hiknoengine_public_header}
|
||||
${hiknoengine_public_header_model}
|
||||
${hiknoengine_src})
|
||||
|
||||
set_target_properties(hiknoengine
|
||||
PROPERTIES
|
||||
LINKER_LANGUAGE CXX
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
|
||||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||||
OUTPUT_NAME ${TARGET_OUTPUT_NAME_PREFIX}hiknoengine
|
||||
)
|
||||
|
||||
if(${LIB_TYPE} STREQUAL "SHARED")
|
||||
set_target_properties(hiknoengine
|
||||
PROPERTIES
|
||||
DEFINE_SYMBOL ALIBABACLOUD_HIKNOENGINE_LIBRARY)
|
||||
endif()
|
||||
|
||||
target_include_directories(hiknoengine
|
||||
PRIVATE include
|
||||
${CMAKE_SOURCE_DIR}/core/include
|
||||
)
|
||||
target_link_libraries(hiknoengine
|
||||
core)
|
||||
|
||||
if(CMAKE_HOST_WIN32)
|
||||
ExternalProject_Get_Property(jsoncpp INSTALL_DIR)
|
||||
set(jsoncpp_install_dir ${INSTALL_DIR})
|
||||
add_dependencies(hiknoengine
|
||||
jsoncpp)
|
||||
target_include_directories(hiknoengine
|
||||
PRIVATE ${jsoncpp_install_dir}/include)
|
||||
target_link_libraries(hiknoengine
|
||||
${jsoncpp_install_dir}/lib/jsoncpp.lib)
|
||||
set_target_properties(hiknoengine
|
||||
PROPERTIES
|
||||
COMPILE_OPTIONS "/bigobj")
|
||||
else()
|
||||
target_include_directories(hiknoengine
|
||||
PRIVATE /usr/include/jsoncpp)
|
||||
target_link_libraries(hiknoengine
|
||||
jsoncpp)
|
||||
endif()
|
||||
|
||||
install(FILES ${hiknoengine_public_header}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/alibabacloud/hiknoengine)
|
||||
install(FILES ${hiknoengine_public_header_model}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/alibabacloud/hiknoengine/model)
|
||||
install(TARGETS hiknoengine
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
|
||||
*
|
||||
* 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 ALIBABACLOUD_HIKNOENGINE_HIKNOENGINECLIENT_H_
|
||||
#define ALIBABACLOUD_HIKNOENGINE_HIKNOENGINECLIENT_H_
|
||||
|
||||
#include <future>
|
||||
#include <alibabacloud/core/AsyncCallerContext.h>
|
||||
#include <alibabacloud/core/EndpointProvider.h>
|
||||
#include <alibabacloud/core/RpcServiceClient.h>
|
||||
#include "HiknoengineExport.h"
|
||||
#include "model/TranslateTextRequest.h"
|
||||
#include "model/TranslateTextResult.h"
|
||||
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Hiknoengine
|
||||
{
|
||||
class ALIBABACLOUD_HIKNOENGINE_EXPORT HiknoengineClient : public RpcServiceClient
|
||||
{
|
||||
public:
|
||||
typedef Outcome<Error, Model::TranslateTextResult> TranslateTextOutcome;
|
||||
typedef std::future<TranslateTextOutcome> TranslateTextOutcomeCallable;
|
||||
typedef std::function<void(const HiknoengineClient*, const Model::TranslateTextRequest&, const TranslateTextOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> TranslateTextAsyncHandler;
|
||||
|
||||
HiknoengineClient(const Credentials &credentials, const ClientConfiguration &configuration);
|
||||
HiknoengineClient(const std::shared_ptr<CredentialsProvider> &credentialsProvider, const ClientConfiguration &configuration);
|
||||
HiknoengineClient(const std::string &accessKeyId, const std::string &accessKeySecret, const ClientConfiguration &configuration);
|
||||
~HiknoengineClient();
|
||||
TranslateTextOutcome translateText(const Model::TranslateTextRequest &request)const;
|
||||
void translateTextAsync(const Model::TranslateTextRequest& request, const TranslateTextAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
|
||||
TranslateTextOutcomeCallable translateTextCallable(const Model::TranslateTextRequest& request) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<EndpointProvider> endpointProvider_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !ALIBABACLOUD_HIKNOENGINE_HIKNOENGINECLIENT_H_
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
|
||||
*
|
||||
* 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 ALIBABACLOUD_HIKNOENGINE_HIKNOENGINEEXPORT_H_
|
||||
#define ALIBABACLOUD_HIKNOENGINE_HIKNOENGINEEXPORT_H_
|
||||
|
||||
#include <alibabacloud/core/Global.h>
|
||||
|
||||
#if defined(ALIBABACLOUD_SHARED)
|
||||
# if defined(ALIBABACLOUD_HIKNOENGINE_LIBRARY)
|
||||
# define ALIBABACLOUD_HIKNOENGINE_EXPORT ALIBABACLOUD_DECL_EXPORT
|
||||
# else
|
||||
# define ALIBABACLOUD_HIKNOENGINE_EXPORT ALIBABACLOUD_DECL_IMPORT
|
||||
# endif
|
||||
#else
|
||||
# define ALIBABACLOUD_HIKNOENGINE_EXPORT
|
||||
#endif
|
||||
|
||||
#endif // !ALIBABACLOUD_HIKNOENGINE_HIKNOENGINEEXPORT_H_
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
|
||||
*
|
||||
* 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 ALIBABACLOUD_HIKNOENGINE_MODEL_TRANSLATETEXTREQUEST_H_
|
||||
#define ALIBABACLOUD_HIKNOENGINE_MODEL_TRANSLATETEXTREQUEST_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <alibabacloud/core/RpcServiceRequest.h>
|
||||
#include <alibabacloud/hiknoengine/HiknoengineExport.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Hiknoengine
|
||||
{
|
||||
namespace Model
|
||||
{
|
||||
class ALIBABACLOUD_HIKNOENGINE_EXPORT TranslateTextRequest : public RpcServiceRequest
|
||||
{
|
||||
|
||||
public:
|
||||
TranslateTextRequest();
|
||||
~TranslateTextRequest();
|
||||
|
||||
std::string getFromLang()const;
|
||||
void setFromLang(const std::string& fromLang);
|
||||
std::string getToLang()const;
|
||||
void setToLang(const std::string& toLang);
|
||||
std::string getText()const;
|
||||
void setText(const std::string& text);
|
||||
|
||||
private:
|
||||
std::string fromLang_;
|
||||
std::string toLang_;
|
||||
std::string text_;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !ALIBABACLOUD_HIKNOENGINE_MODEL_TRANSLATETEXTREQUEST_H_
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
|
||||
*
|
||||
* 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 ALIBABACLOUD_HIKNOENGINE_MODEL_TRANSLATETEXTRESULT_H_
|
||||
#define ALIBABACLOUD_HIKNOENGINE_MODEL_TRANSLATETEXTRESULT_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <alibabacloud/core/ServiceResult.h>
|
||||
#include <alibabacloud/hiknoengine/HiknoengineExport.h>
|
||||
|
||||
namespace AlibabaCloud
|
||||
{
|
||||
namespace Hiknoengine
|
||||
{
|
||||
namespace Model
|
||||
{
|
||||
class ALIBABACLOUD_HIKNOENGINE_EXPORT TranslateTextResult : public ServiceResult
|
||||
{
|
||||
public:
|
||||
struct Data
|
||||
{
|
||||
std::string text;
|
||||
};
|
||||
|
||||
|
||||
TranslateTextResult();
|
||||
explicit TranslateTextResult(const std::string &payload);
|
||||
~TranslateTextResult();
|
||||
std::string getMessage()const;
|
||||
Data getData()const;
|
||||
std::string getCode()const;
|
||||
|
||||
protected:
|
||||
void parse(const std::string &payload);
|
||||
private:
|
||||
std::string message_;
|
||||
Data data_;
|
||||
std::string code_;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !ALIBABACLOUD_HIKNOENGINE_MODEL_TRANSLATETEXTRESULT_H_
|
||||
89
hiknoengine/src/HiknoengineClient.cc
Normal file
89
hiknoengine/src/HiknoengineClient.cc
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <alibabacloud/hiknoengine/HiknoengineClient.h>
|
||||
#include <alibabacloud/core/SimpleCredentialsProvider.h>
|
||||
|
||||
using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Location;
|
||||
using namespace AlibabaCloud::Hiknoengine;
|
||||
using namespace AlibabaCloud::Hiknoengine::Model;
|
||||
|
||||
namespace
|
||||
{
|
||||
const std::string SERVICE_NAME = "hiknoengine";
|
||||
}
|
||||
|
||||
HiknoengineClient::HiknoengineClient(const Credentials &credentials, const ClientConfiguration &configuration) :
|
||||
RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
|
||||
{
|
||||
auto locationClient = std::make_shared<LocationClient>(credentials, configuration);
|
||||
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "hiknoengine");
|
||||
}
|
||||
|
||||
HiknoengineClient::HiknoengineClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
|
||||
RpcServiceClient(SERVICE_NAME, credentialsProvider, configuration)
|
||||
{
|
||||
auto locationClient = std::make_shared<LocationClient>(credentialsProvider, configuration);
|
||||
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "hiknoengine");
|
||||
}
|
||||
|
||||
HiknoengineClient::HiknoengineClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
|
||||
RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
|
||||
{
|
||||
auto locationClient = std::make_shared<LocationClient>(accessKeyId, accessKeySecret, configuration);
|
||||
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "hiknoengine");
|
||||
}
|
||||
|
||||
HiknoengineClient::~HiknoengineClient()
|
||||
{}
|
||||
|
||||
HiknoengineClient::TranslateTextOutcome HiknoengineClient::translateText(const TranslateTextRequest &request) const
|
||||
{
|
||||
auto endpointOutcome = endpointProvider_->getEndpoint();
|
||||
if (!endpointOutcome.isSuccess())
|
||||
return TranslateTextOutcome(endpointOutcome.error());
|
||||
|
||||
auto outcome = makeRequest(endpointOutcome.result(), request);
|
||||
|
||||
if (outcome.isSuccess())
|
||||
return TranslateTextOutcome(TranslateTextResult(outcome.result()));
|
||||
else
|
||||
return TranslateTextOutcome(outcome.error());
|
||||
}
|
||||
|
||||
void HiknoengineClient::translateTextAsync(const TranslateTextRequest& request, const TranslateTextAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
|
||||
{
|
||||
auto fn = [this, request, handler, context]()
|
||||
{
|
||||
handler(this, request, translateText(request), context);
|
||||
};
|
||||
|
||||
asyncExecute(new Runnable(fn));
|
||||
}
|
||||
|
||||
HiknoengineClient::TranslateTextOutcomeCallable HiknoengineClient::translateTextCallable(const TranslateTextRequest &request) const
|
||||
{
|
||||
auto task = std::make_shared<std::packaged_task<TranslateTextOutcome()>>(
|
||||
[this, request]()
|
||||
{
|
||||
return this->translateText(request);
|
||||
});
|
||||
|
||||
asyncExecute(new Runnable([task]() { (*task)(); }));
|
||||
return task->get_future();
|
||||
}
|
||||
|
||||
62
hiknoengine/src/model/TranslateTextRequest.cc
Normal file
62
hiknoengine/src/model/TranslateTextRequest.cc
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <alibabacloud/hiknoengine/model/TranslateTextRequest.h>
|
||||
|
||||
using AlibabaCloud::Hiknoengine::Model::TranslateTextRequest;
|
||||
|
||||
TranslateTextRequest::TranslateTextRequest() :
|
||||
RpcServiceRequest("hiknoengine", "2019-06-25", "TranslateText")
|
||||
{
|
||||
setMethod(HttpRequest::Method::Post);
|
||||
}
|
||||
|
||||
TranslateTextRequest::~TranslateTextRequest()
|
||||
{}
|
||||
|
||||
std::string TranslateTextRequest::getFromLang()const
|
||||
{
|
||||
return fromLang_;
|
||||
}
|
||||
|
||||
void TranslateTextRequest::setFromLang(const std::string& fromLang)
|
||||
{
|
||||
fromLang_ = fromLang;
|
||||
setCoreParameter("FromLang", fromLang);
|
||||
}
|
||||
|
||||
std::string TranslateTextRequest::getToLang()const
|
||||
{
|
||||
return toLang_;
|
||||
}
|
||||
|
||||
void TranslateTextRequest::setToLang(const std::string& toLang)
|
||||
{
|
||||
toLang_ = toLang;
|
||||
setCoreParameter("ToLang", toLang);
|
||||
}
|
||||
|
||||
std::string TranslateTextRequest::getText()const
|
||||
{
|
||||
return text_;
|
||||
}
|
||||
|
||||
void TranslateTextRequest::setText(const std::string& text)
|
||||
{
|
||||
text_ = text;
|
||||
setCoreParameter("Text", text);
|
||||
}
|
||||
|
||||
66
hiknoengine/src/model/TranslateTextResult.cc
Normal file
66
hiknoengine/src/model/TranslateTextResult.cc
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <alibabacloud/hiknoengine/model/TranslateTextResult.h>
|
||||
#include <json/json.h>
|
||||
|
||||
using namespace AlibabaCloud::Hiknoengine;
|
||||
using namespace AlibabaCloud::Hiknoengine::Model;
|
||||
|
||||
TranslateTextResult::TranslateTextResult() :
|
||||
ServiceResult()
|
||||
{}
|
||||
|
||||
TranslateTextResult::TranslateTextResult(const std::string &payload) :
|
||||
ServiceResult()
|
||||
{
|
||||
parse(payload);
|
||||
}
|
||||
|
||||
TranslateTextResult::~TranslateTextResult()
|
||||
{}
|
||||
|
||||
void TranslateTextResult::parse(const std::string &payload)
|
||||
{
|
||||
Json::Reader reader;
|
||||
Json::Value value;
|
||||
reader.parse(payload, value);
|
||||
setRequestId(value["RequestId"].asString());
|
||||
auto dataNode = value["Data"];
|
||||
if(!dataNode["Text"].isNull())
|
||||
data_.text = dataNode["Text"].asString();
|
||||
if(!value["Code"].isNull())
|
||||
code_ = value["Code"].asString();
|
||||
if(!value["Message"].isNull())
|
||||
message_ = value["Message"].asString();
|
||||
|
||||
}
|
||||
|
||||
std::string TranslateTextResult::getMessage()const
|
||||
{
|
||||
return message_;
|
||||
}
|
||||
|
||||
TranslateTextResult::Data TranslateTextResult::getData()const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
|
||||
std::string TranslateTextResult::getCode()const
|
||||
{
|
||||
return code_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user