diff --git a/.gitignore b/.gitignore index eeb8963e649..035ef974032 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ target/ !.gitignore !.gitkeep !.travis.yml +tubemq-client-twins/tubemq-client-cpp/build/ diff --git a/tubemq-client-twins/tubemq-client-cpp/CMakeLists.txt b/tubemq-client-twins/tubemq-client-cpp/CMakeLists.txt new file mode 100644 index 00000000000..db9014abd18 --- /dev/null +++ b/tubemq-client-twins/tubemq-client-cpp/CMakeLists.txt @@ -0,0 +1,50 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + + +cmake_minimum_required (VERSION 3.1) + +project (TubeMQ) + + +INCLUDE_DIRECTORIES(include) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/third_party/rapidjson/include) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/third_party/log4cplus/include) +INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/third_party/log4cplus/include) +LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/third_party/log4cplus/lib) + +ADD_SUBDIRECTORY(src) +ADD_SUBDIRECTORY(third_party) +ADD_SUBDIRECTORY(example) + + +if (UNIX) + SET(CMAKE_CXX_FLAGS_DEBUG "-O1 -g -ggdb -D_DEBUG") + SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -g -ggdb -DNDEBUG") + SET(DEPENDENT_LIBRARIES log4cplus pthread) +else (UNIX) + SET(DEPENDENT_LIBRARIES log4cplus) +endif (UNIX) + + + + + + diff --git a/tubemq-client-twins/tubemq-client-cpp/build_linux.sh b/tubemq-client-twins/tubemq-client-cpp/build_linux.sh new file mode 100755 index 00000000000..be79e90110a --- /dev/null +++ b/tubemq-client-twins/tubemq-client-cpp/build_linux.sh @@ -0,0 +1,31 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + + +#!/bin/bash + +cd ../../ +git submodule foreach --recursive git submodule init +git submodule foreach --recursive git submodule update +cd - + +mkdir build +cd build +cmake ../ +make diff --git a/tubemq-client-twins/tubemq-client-cpp/example/CMakeLists.txt b/tubemq-client-twins/tubemq-client-cpp/example/CMakeLists.txt new file mode 100644 index 00000000000..1d8fcddf865 --- /dev/null +++ b/tubemq-client-twins/tubemq-client-cpp/example/CMakeLists.txt @@ -0,0 +1,32 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + + +# A function to set up a test, since it's the same for each one. Note: +# unit_tests test is not set up using this function because it does not like +# the additional argument on commmand line and consequently does not run any +# test. +function(tubemq_add_example _name) + set(_srcs ${ARGN}) + message (STATUS "${_name} sources: ${_srcs}") + add_executable (${_name} ${_srcs}) + TARGET_LINK_LIBRARIES (${_name} tubemq log4cplus pthread) +endfunction() + +add_subdirectory (log) diff --git a/tubemq-client-twins/tubemq-client-cpp/example/log/CMakeLists.txt b/tubemq-client-twins/tubemq-client-cpp/example/log/CMakeLists.txt new file mode 100644 index 00000000000..b828bf8682e --- /dev/null +++ b/tubemq-client-twins/tubemq-client-cpp/example/log/CMakeLists.txt @@ -0,0 +1,21 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + + +tubemq_add_example(log main.cc) diff --git a/tubemq-client-twins/tubemq-client-cpp/example/log/main.cc b/tubemq-client-twins/tubemq-client-cpp/example/log/main.cc index f21d0221f01..9bb16853947 100644 --- a/tubemq-client-twins/tubemq-client-cpp/example/log/main.cc +++ b/tubemq-client-twins/tubemq-client-cpp/example/log/main.cc @@ -23,7 +23,7 @@ #include #include -#include "logger.h" +#include "tubemq/logger.h" using namespace std; using namespace tubemq; diff --git a/tubemq-client-twins/tubemq-client-cpp/include/tubemq/logger.h b/tubemq-client-twins/tubemq-client-cpp/include/tubemq/logger.h index eb35075f851..74d083c8858 100644 --- a/tubemq-client-twins/tubemq-client-cpp/include/tubemq/logger.h +++ b/tubemq-client-twins/tubemq-client-cpp/include/tubemq/logger.h @@ -98,11 +98,7 @@ class Logger { static const char* Level2String(Level level) { static const char* level_names[] = { - "TRACE", - "DEBUG" - "INFO", - "WARN", - "ERROR", + "TRACE", "DEBUG", "INFO", "WARN", "ERROR", }; return level_names[level]; } diff --git a/tubemq-client-twins/tubemq-client-cpp/src/CMakeLists.txt b/tubemq-client-twins/tubemq-client-cpp/src/CMakeLists.txt new file mode 100644 index 00000000000..a6e76e52981 --- /dev/null +++ b/tubemq-client-twins/tubemq-client-cpp/src/CMakeLists.txt @@ -0,0 +1,32 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + + +cmake_minimum_required (VERSION 3.1) + + +set(CMAKE_C_FLAGS "-O2 -g -Wall -Werror -Wsign-compare -fno-strict-aliasing -fPIC") +set(CMAKE_CXX_FLAGS "-std=c++11 -O2 -g -Wall -Werror -Wsign-compare -fno-strict-aliasing -fPIC") + +AUX_SOURCE_DIRECTORY(. CURRENT_DIR_SRCS) +ADD_LIBRARY(tubemq STATIC ${CURRENT_DIR_SRCS}) +TARGET_LINK_LIBRARIES (tubemq) + + + diff --git a/tubemq-client-twins/tubemq-client-cpp/src/client_config.cc b/tubemq-client-twins/tubemq-client-cpp/src/client_config.cc index b623497676a..dfd5b8c77d1 100644 --- a/tubemq-client-twins/tubemq-client-cpp/src/client_config.cc +++ b/tubemq-client-twins/tubemq-client-cpp/src/client_config.cc @@ -28,11 +28,10 @@ namespace tubemq { -using std::stringstream; using std::set; +using std::stringstream; using std::vector; - BaseConfig::BaseConfig() { this->master_addrinfo_ = ""; this->auth_enable_ = false; @@ -335,8 +334,8 @@ bool ConsumerConfig::setGroupConsumeTarget( string tmp_filteritem; set tgt_filters; // check topic_name info - is_success = - Utils::ValidString(err_info, it_map->first, false, true, true, tb_config::kTopicNameMaxLength); + is_success = Utils::ValidString(err_info, it_map->first, false, true, true, + tb_config::kTopicNameMaxLength); if (!is_success) { stringstream ss; ss << "Check parameter subscribed_topic_and_filter_map error: topic "; @@ -503,7 +502,7 @@ void ConsumerConfig::SetWaitPeriodIfConfirmWaitRebalanceMs(int reb_confirm_wait_ this->reb_confirm_wait_period_ms_ = reb_confirm_wait_period_ms; } -const int ConsumerConfig::GetMaxConfirmWaitPeriodMs() const { this->max_confirm_wait_period_ms_; } +const int ConsumerConfig::GetMaxConfirmWaitPeriodMs() const { return max_confirm_wait_period_ms_; } void ConsumerConfig::SetMaxConfirmWaitPeriodMs(int max_confirm_wait_period_ms) { this->max_confirm_wait_period_ms_ = max_confirm_wait_period_ms; diff --git a/tubemq-client-twins/tubemq-client-cpp/src/flowctrl_def.cc b/tubemq-client-twins/tubemq-client-cpp/src/flowctrl_def.cc index f5c90a850de..370e6e68b47 100644 --- a/tubemq-client-twins/tubemq-client-cpp/src/flowctrl_def.cc +++ b/tubemq-client-twins/tubemq-client-cpp/src/flowctrl_def.cc @@ -178,14 +178,13 @@ FlowCtrlRuleHandler::~FlowCtrlRuleHandler() { pthread_rwlock_destroy(&configrw_l void FlowCtrlRuleHandler::UpdateDefFlowCtrlInfo(bool is_default, int32_t qrypriority_id, int64_t flowctrl_id, const string& flowctrl_info) { - bool result; map > tmp_flowctrl_map; if (flowctrl_id == this->flowctrl_id_.Get()) { return; } int64_t curr_flowctrl_id = this->flowctrl_id_.Get(); if (flowctrl_info.length() > 0) { - result = parseFlowCtrlInfo(flowctrl_info, tmp_flowctrl_map); + parseFlowCtrlInfo(flowctrl_info, tmp_flowctrl_map); } pthread_rwlock_wrlock(&this->configrw_lock_); this->flowctrl_id_.Set(flowctrl_id); @@ -266,7 +265,8 @@ void FlowCtrlRuleHandler::clearStatisData() { this->filter_ctrl_item_.Clear(); } -bool FlowCtrlRuleHandler::GetCurDataLimit(int64_t last_datadlt, FlowCtrlResult& flowctrl_result) const { +bool FlowCtrlRuleHandler::GetCurDataLimit(int64_t last_datadlt, + FlowCtrlResult& flowctrl_result) const { struct tm utc_tm; vector::const_iterator it_vec; map >::const_iterator it_map; @@ -291,7 +291,8 @@ bool FlowCtrlRuleHandler::GetCurDataLimit(int64_t last_datadlt, FlowCtrlResult& return false; } -int32_t FlowCtrlRuleHandler::GetCurFreqLimitTime(int32_t msg_zero_cnt, int32_t received_limit) const { +int32_t FlowCtrlRuleHandler::GetCurFreqLimitTime(int32_t msg_zero_cnt, + int32_t received_limit) const { int32_t rule_val = -2; vector::const_iterator it_vec; map >::const_iterator it_map; @@ -402,7 +403,6 @@ bool FlowCtrlRuleHandler::parseDataLimit(string& err_info, const rapidjson::Valu int32_t type_val; stringstream ss; string attr_sep = delimiter::kDelimiterColon; - string::size_type pos1; if (!parseIntMember(err_info, root, "type", type_val, true, 0)) { ss << "Decode Failure: "; ss << err_info; @@ -573,13 +573,13 @@ bool FlowCtrlRuleHandler::parseLowFetchLimit(string& err_info, const rapidjson:: return false; } // parse rule info - const rapidjson::Value& node_item = root["rule"]; - for (uint32_t i = 0; i < node_item.Size(); i++) { + const rapidjson::Value& nodes = root["rule"]; + for (uint32_t i = 0; i < nodes.Size(); ++i) { int32_t norm_freq_ms = 0; int32_t filter_freq_ms = 0; int32_t min_filter_freq_ms = 0; FlowCtrlItem flowctrl_item; - const rapidjson::Value& node_item = node_item[i]; + const rapidjson::Value& node_item = nodes[i]; if (!node_item.IsObject()) { err_info = "Illegal rule'value item, must be dict type"; return false; diff --git a/tubemq-client-twins/tubemq-client-cpp/third_party/CMakeLists.txt b/tubemq-client-twins/tubemq-client-cpp/third_party/CMakeLists.txt new file mode 100644 index 00000000000..7dc5e883c3f --- /dev/null +++ b/tubemq-client-twins/tubemq-client-cpp/third_party/CMakeLists.txt @@ -0,0 +1,25 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + + +CMAKE_MINIMUM_REQUIRED(VERSION 3.1) +PROJECT(TubeMQThirdParty) + +ADD_SUBDIRECTORY(log4cplus) + diff --git a/tubemq-client-twins/tubemq-client-cpp/third_party/log4cplus b/tubemq-client-twins/tubemq-client-cpp/third_party/log4cplus index 76ff7e68c35..9d00f7d10f2 160000 --- a/tubemq-client-twins/tubemq-client-cpp/third_party/log4cplus +++ b/tubemq-client-twins/tubemq-client-cpp/third_party/log4cplus @@ -1 +1 @@ -Subproject commit 76ff7e68c35e277440d414ba782eceedad8db7b1 +Subproject commit 9d00f7d10f2507f68f9ab5fea8b842735d9c6cfe