diff --git a/VERSION b/VERSION index 06fc57828..3f6403ee6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.36.2087 \ No newline at end of file +1.36.2088 \ No newline at end of file diff --git a/lingmou/CMakeLists.txt b/lingmou/CMakeLists.txt new file mode 100644 index 000000000..016f7e3b6 --- /dev/null +++ b/lingmou/CMakeLists.txt @@ -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(lingmou_public_header + include/alibabacloud/lingmou/LingMouClient.h + include/alibabacloud/lingmou/LingMouExport.h ) + +set(lingmou_public_header_model + include/alibabacloud/lingmou/model/CreateChatSessionRequest.h + include/alibabacloud/lingmou/model/CreateChatSessionResult.h ) + +set(lingmou_src + src/LingMouClient.cc + src/model/CreateChatSessionRequest.cc + src/model/CreateChatSessionResult.cc ) + +add_library(lingmou ${LIB_TYPE} + ${lingmou_public_header} + ${lingmou_public_header_model} + ${lingmou_src}) + +set_target_properties(lingmou + 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}lingmou + ) + +if(${LIB_TYPE} STREQUAL "SHARED") + set_target_properties(lingmou + PROPERTIES + DEFINE_SYMBOL ALIBABACLOUD_LINGMOU_LIBRARY) +endif() + +target_include_directories(lingmou + PRIVATE include + ${CMAKE_SOURCE_DIR}/core/include + ) +target_link_libraries(lingmou + core) + +if(CMAKE_HOST_WIN32) + ExternalProject_Get_Property(jsoncpp INSTALL_DIR) + set(jsoncpp_install_dir ${INSTALL_DIR}) + add_dependencies(lingmou + jsoncpp) + target_include_directories(lingmou + PRIVATE ${jsoncpp_install_dir}/include) + target_link_libraries(lingmou + ${jsoncpp_install_dir}/lib/jsoncpp.lib) + set_target_properties(lingmou + PROPERTIES + COMPILE_OPTIONS "/bigobj") +else() + target_include_directories(lingmou + PRIVATE /usr/include/jsoncpp) + target_link_libraries(lingmou + jsoncpp) +endif() + +install(FILES ${lingmou_public_header} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/alibabacloud/lingmou) +install(FILES ${lingmou_public_header_model} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/alibabacloud/lingmou/model) +install(TARGETS lingmou + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) \ No newline at end of file diff --git a/lingmou/include/alibabacloud/lingmou/LingMouClient.h b/lingmou/include/alibabacloud/lingmou/LingMouClient.h new file mode 100644 index 000000000..dfe5db5ef --- /dev/null +++ b/lingmou/include/alibabacloud/lingmou/LingMouClient.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_LINGMOU_LINGMOUCLIENT_H_ +#define ALIBABACLOUD_LINGMOU_LINGMOUCLIENT_H_ + +#include +#include +#include +#include +#include "LingMouExport.h" +#include "model/CreateChatSessionRequest.h" +#include "model/CreateChatSessionResult.h" + + +namespace AlibabaCloud +{ + namespace LingMou + { + class ALIBABACLOUD_LINGMOU_EXPORT LingMouClient : public RoaServiceClient + { + public: + typedef Outcome CreateChatSessionOutcome; + typedef std::future CreateChatSessionOutcomeCallable; + typedef std::function&)> CreateChatSessionAsyncHandler; + + LingMouClient(const Credentials &credentials, const ClientConfiguration &configuration); + LingMouClient(const std::shared_ptr &credentialsProvider, const ClientConfiguration &configuration); + LingMouClient(const std::string &accessKeyId, const std::string &accessKeySecret, const ClientConfiguration &configuration); + ~LingMouClient(); + CreateChatSessionOutcome createChatSession(const Model::CreateChatSessionRequest &request)const; + void createChatSessionAsync(const Model::CreateChatSessionRequest& request, const CreateChatSessionAsyncHandler& handler, const std::shared_ptr& context = nullptr) const; + CreateChatSessionOutcomeCallable createChatSessionCallable(const Model::CreateChatSessionRequest& request) const; + + private: + std::shared_ptr endpointProvider_; + }; + } +} + +#endif // !ALIBABACLOUD_LINGMOU_LINGMOUCLIENT_H_ diff --git a/lingmou/include/alibabacloud/lingmou/LingMouExport.h b/lingmou/include/alibabacloud/lingmou/LingMouExport.h new file mode 100644 index 000000000..8e3edecc7 --- /dev/null +++ b/lingmou/include/alibabacloud/lingmou/LingMouExport.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_LINGMOU_LINGMOUEXPORT_H_ +#define ALIBABACLOUD_LINGMOU_LINGMOUEXPORT_H_ + +#include + +#if defined(ALIBABACLOUD_SHARED) +# if defined(ALIBABACLOUD_LINGMOU_LIBRARY) +# define ALIBABACLOUD_LINGMOU_EXPORT ALIBABACLOUD_DECL_EXPORT +# else +# define ALIBABACLOUD_LINGMOU_EXPORT ALIBABACLOUD_DECL_IMPORT +# endif +#else +# define ALIBABACLOUD_LINGMOU_EXPORT +#endif + +#endif // !ALIBABACLOUD_LINGMOU_LINGMOUEXPORT_H_ \ No newline at end of file diff --git a/lingmou/include/alibabacloud/lingmou/model/CreateChatSessionRequest.h b/lingmou/include/alibabacloud/lingmou/model/CreateChatSessionRequest.h new file mode 100644 index 000000000..4636d9440 --- /dev/null +++ b/lingmou/include/alibabacloud/lingmou/model/CreateChatSessionRequest.h @@ -0,0 +1,51 @@ +/* + * 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_LINGMOU_MODEL_CREATECHATSESSIONREQUEST_H_ +#define ALIBABACLOUD_LINGMOU_MODEL_CREATECHATSESSIONREQUEST_H_ + +#include +#include +#include +#include +#include + +namespace AlibabaCloud { +namespace LingMou { +namespace Model { +class ALIBABACLOUD_LINGMOU_EXPORT CreateChatSessionRequest : public RoaServiceRequest { +public: + CreateChatSessionRequest(); + ~CreateChatSessionRequest(); + std::string getLicense() const; + void setLicense(const std::string &license); + std::string getInstanceId() const; + void setInstanceId(const std::string &instanceId); + std::string getId() const; + void setId(const std::string &id); + std::string getPlatform() const; + void setPlatform(const std::string &platform); + +private: + std::string license_; + std::string instanceId_; + std::string id_; + std::string platform_; +}; +} // namespace Model +} // namespace LingMou +} // namespace AlibabaCloud +#endif // !ALIBABACLOUD_LINGMOU_MODEL_CREATECHATSESSIONREQUEST_H_ diff --git a/lingmou/include/alibabacloud/lingmou/model/CreateChatSessionResult.h b/lingmou/include/alibabacloud/lingmou/model/CreateChatSessionResult.h new file mode 100644 index 000000000..574efb829 --- /dev/null +++ b/lingmou/include/alibabacloud/lingmou/model/CreateChatSessionResult.h @@ -0,0 +1,87 @@ +/* + * 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_LINGMOU_MODEL_CREATECHATSESSIONRESULT_H_ +#define ALIBABACLOUD_LINGMOU_MODEL_CREATECHATSESSIONRESULT_H_ + +#include +#include +#include +#include +#include + +namespace AlibabaCloud +{ + namespace LingMou + { + namespace Model + { + class ALIBABACLOUD_LINGMOU_EXPORT CreateChatSessionResult : public ServiceResult + { + public: + struct Data + { + struct RtcParams + { + std::string gslb; + std::string nonce; + std::string appId; + std::string serverUserId; + std::string channel; + std::string token; + std::string avatarUserId; + std::string clientUserId; + long timestamp; + }; + struct AvatarAssets + { + std::string secret; + std::string type; + std::string minRequiredVersion; + std::string url; + std::string md5; + }; + AvatarAssets avatarAssets; + RtcParams rtcParams; + std::string sessionId; + }; + + + CreateChatSessionResult(); + explicit CreateChatSessionResult(const std::string &payload); + ~CreateChatSessionResult(); + std::string getRequestId()const; + std::string getMessage()const; + long getHttpStatusCode()const; + Data getData()const; + std::string getCode()const; + bool getSuccess()const; + + protected: + void parse(const std::string &payload); + private: + std::string requestId_; + std::string message_; + long httpStatusCode_; + Data data_; + std::string code_; + bool success_; + + }; + } + } +} +#endif // !ALIBABACLOUD_LINGMOU_MODEL_CREATECHATSESSIONRESULT_H_ \ No newline at end of file diff --git a/lingmou/src/LingMouClient.cc b/lingmou/src/LingMouClient.cc new file mode 100644 index 000000000..cae77ea51 --- /dev/null +++ b/lingmou/src/LingMouClient.cc @@ -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 +#include + +using namespace AlibabaCloud; +using namespace AlibabaCloud::Location; +using namespace AlibabaCloud::LingMou; +using namespace AlibabaCloud::LingMou::Model; + +namespace +{ + const std::string SERVICE_NAME = "LingMou"; +} + +LingMouClient::LingMouClient(const Credentials &credentials, const ClientConfiguration &configuration) : + RoaServiceClient(SERVICE_NAME, std::make_shared(credentials), configuration) +{ + auto locationClient = std::make_shared(credentials, configuration); + endpointProvider_ = std::make_shared(locationClient, configuration.regionId(), SERVICE_NAME, ""); +} + +LingMouClient::LingMouClient(const std::shared_ptr& credentialsProvider, const ClientConfiguration & configuration) : + RoaServiceClient(SERVICE_NAME, credentialsProvider, configuration) +{ + auto locationClient = std::make_shared(credentialsProvider, configuration); + endpointProvider_ = std::make_shared(locationClient, configuration.regionId(), SERVICE_NAME, ""); +} + +LingMouClient::LingMouClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) : + RoaServiceClient(SERVICE_NAME, std::make_shared(accessKeyId, accessKeySecret), configuration) +{ + auto locationClient = std::make_shared(accessKeyId, accessKeySecret, configuration); + endpointProvider_ = std::make_shared(locationClient, configuration.regionId(), SERVICE_NAME, ""); +} + +LingMouClient::~LingMouClient() +{} + +LingMouClient::CreateChatSessionOutcome LingMouClient::createChatSession(const CreateChatSessionRequest &request) const +{ + auto endpointOutcome = endpointProvider_->getEndpoint(); + if (!endpointOutcome.isSuccess()) + return CreateChatSessionOutcome(endpointOutcome.error()); + + auto outcome = makeRequest(endpointOutcome.result(), request); + + if (outcome.isSuccess()) + return CreateChatSessionOutcome(CreateChatSessionResult(outcome.result())); + else + return CreateChatSessionOutcome(outcome.error()); +} + +void LingMouClient::createChatSessionAsync(const CreateChatSessionRequest& request, const CreateChatSessionAsyncHandler& handler, const std::shared_ptr& context) const +{ + auto fn = [this, request, handler, context]() + { + handler(this, request, createChatSession(request), context); + }; + + asyncExecute(new Runnable(fn)); +} + +LingMouClient::CreateChatSessionOutcomeCallable LingMouClient::createChatSessionCallable(const CreateChatSessionRequest &request) const +{ + auto task = std::make_shared>( + [this, request]() + { + return this->createChatSession(request); + }); + + asyncExecute(new Runnable([task]() { (*task)(); })); + return task->get_future(); +} + diff --git a/lingmou/src/model/CreateChatSessionRequest.cc b/lingmou/src/model/CreateChatSessionRequest.cc new file mode 100644 index 000000000..dd2f99a63 --- /dev/null +++ b/lingmou/src/model/CreateChatSessionRequest.cc @@ -0,0 +1,64 @@ +/* + * 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 + +using AlibabaCloud::LingMou::Model::CreateChatSessionRequest; + +CreateChatSessionRequest::CreateChatSessionRequest() + : RoaServiceRequest("lingmou", "2025-05-27") { + setResourcePath("/openapi/chat/init/[id]"}; + setMethod(HttpRequest::Method::Post); +} + +CreateChatSessionRequest::~CreateChatSessionRequest() {} + +std::string CreateChatSessionRequest::getLicense() const { + return license_; +} + +void CreateChatSessionRequest::setLicense(const std::string &license) { + license_ = license; + setParameter(std::string("license"), license); +} + +std::string CreateChatSessionRequest::getInstanceId() const { + return instanceId_; +} + +void CreateChatSessionRequest::setInstanceId(const std::string &instanceId) { + instanceId_ = instanceId; + setParameter(std::string("instanceId"), instanceId); +} + +std::string CreateChatSessionRequest::getId() const { + return id_; +} + +void CreateChatSessionRequest::setId(const std::string &id) { + id_ = id; + setParameter(std::string("id"), id); +} + +std::string CreateChatSessionRequest::getPlatform() const { + return platform_; +} + +void CreateChatSessionRequest::setPlatform(const std::string &platform) { + platform_ = platform; + setParameter(std::string("platform"), platform); +} + diff --git a/lingmou/src/model/CreateChatSessionResult.cc b/lingmou/src/model/CreateChatSessionResult.cc new file mode 100644 index 000000000..0ab590b53 --- /dev/null +++ b/lingmou/src/model/CreateChatSessionResult.cc @@ -0,0 +1,117 @@ +/* + * 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 +#include + +using namespace AlibabaCloud::LingMou; +using namespace AlibabaCloud::LingMou::Model; + +CreateChatSessionResult::CreateChatSessionResult() : + ServiceResult() +{} + +CreateChatSessionResult::CreateChatSessionResult(const std::string &payload) : + ServiceResult() +{ + parse(payload); +} + +CreateChatSessionResult::~CreateChatSessionResult() +{} + +void CreateChatSessionResult::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["sessionId"].isNull()) + data_.sessionId = dataNode["sessionId"].asString(); + auto rtcParamsNode = dataNode["rtcParams"]; + if(!rtcParamsNode["appId"].isNull()) + data_.rtcParams.appId = rtcParamsNode["appId"].asString(); + if(!rtcParamsNode["avatarUserId"].isNull()) + data_.rtcParams.avatarUserId = rtcParamsNode["avatarUserId"].asString(); + if(!rtcParamsNode["channel"].isNull()) + data_.rtcParams.channel = rtcParamsNode["channel"].asString(); + if(!rtcParamsNode["clientUserId"].isNull()) + data_.rtcParams.clientUserId = rtcParamsNode["clientUserId"].asString(); + if(!rtcParamsNode["gslb"].isNull()) + data_.rtcParams.gslb = rtcParamsNode["gslb"].asString(); + if(!rtcParamsNode["nonce"].isNull()) + data_.rtcParams.nonce = rtcParamsNode["nonce"].asString(); + if(!rtcParamsNode["serverUserId"].isNull()) + data_.rtcParams.serverUserId = rtcParamsNode["serverUserId"].asString(); + if(!rtcParamsNode["timestamp"].isNull()) + data_.rtcParams.timestamp = std::stol(rtcParamsNode["timestamp"].asString()); + if(!rtcParamsNode["token"].isNull()) + data_.rtcParams.token = rtcParamsNode["token"].asString(); + auto avatarAssetsNode = dataNode["avatarAssets"]; + if(!avatarAssetsNode["url"].isNull()) + data_.avatarAssets.url = avatarAssetsNode["url"].asString(); + if(!avatarAssetsNode["md5"].isNull()) + data_.avatarAssets.md5 = avatarAssetsNode["md5"].asString(); + if(!avatarAssetsNode["secret"].isNull()) + data_.avatarAssets.secret = avatarAssetsNode["secret"].asString(); + if(!avatarAssetsNode["type"].isNull()) + data_.avatarAssets.type = avatarAssetsNode["type"].asString(); + if(!avatarAssetsNode["minRequiredVersion"].isNull()) + data_.avatarAssets.minRequiredVersion = avatarAssetsNode["minRequiredVersion"].asString(); + if(!value["requestId"].isNull()) + requestId_ = value["requestId"].asString(); + if(!value["message"].isNull()) + message_ = value["message"].asString(); + if(!value["httpStatusCode"].isNull()) + httpStatusCode_ = std::stol(value["httpStatusCode"].asString()); + if(!value["code"].isNull()) + code_ = value["code"].asString(); + if(!value["success"].isNull()) + success_ = value["success"].asString() == "true"; + +} + +std::string CreateChatSessionResult::getRequestId()const +{ + return requestId_; +} + +std::string CreateChatSessionResult::getMessage()const +{ + return message_; +} + +long CreateChatSessionResult::getHttpStatusCode()const +{ + return httpStatusCode_; +} + +CreateChatSessionResult::Data CreateChatSessionResult::getData()const +{ + return data_; +} + +std::string CreateChatSessionResult::getCode()const +{ + return code_; +} + +bool CreateChatSessionResult::getSuccess()const +{ + return success_; +} +