Skip to content

Format the codes and remove warnings #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions example/CBatchProducer.c
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
*/

#include <stdio.h>
#include <string.h>
#include "CBatchMessage.h"
#include "CCommon.h"
#include "CMessage.h"
@@ -38,8 +39,8 @@ void StartSendMessage(CProducer* producer) {
AddMessage(batchMessage, msg);
}
CSendResult result;
int ok = SendBatchMessage(producer, batchMessage, &result);
printf("SendBatchMessage is %s .....\n", ok == 0 ? "Success" : ok == 11 ? "FAILED" : " It is null value");
ret_code = SendBatchMessage(producer, batchMessage, &result);
printf("SendBatchMessage %s .....\n", ret_code == 0 ? "Success" : ret_code == 11 ? "FAILED" : " It is null value");
DestroyBatchMessage(batchMessage);
}

11 changes: 5 additions & 6 deletions include/CErrorMessage.h
Original file line number Diff line number Diff line change
@@ -15,19 +15,18 @@
* limitations under the License.
*/


#ifndef __C_CLIENT_ERROR_H__
#define __C_CLIENT_ERROR_H__
#ifndef __CERROR_MESSAGE_H__
#define __CERROR_MESSAGE_H__

#include "CCommon.h"

#ifdef __cplusplus
extern "C" {
#endif
ROCKETMQCLIENT_API const char *GetLatestErrorMessage(); // Return the last error message

ROCKETMQCLIENT_API const char* GetLatestErrorMessage(); // Return the last error message

#ifdef __cplusplus
};
#endif
#endif //__C_CLIENT_ERROR_H__
#endif //__CERROR_MESSAGE_H__
64 changes: 29 additions & 35 deletions src/common/MQClientErrorContainer.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
#pragma once
/*
* 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.
*/
* 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.
*/


#include "MQClientErrorContainer.h"




namespace rocketmq {
MQClientErrorContainer * MQClientErrorContainer::s_instance = nullptr;
MQClientErrorContainer* MQClientErrorContainer::s_instance = nullptr;

MQClientErrorContainer * MQClientErrorContainer::instance() {
if (!s_instance)
s_instance = new MQClientErrorContainer();
return s_instance;
}
MQClientErrorContainer* MQClientErrorContainer::instance() {
if (!s_instance)
s_instance = new MQClientErrorContainer();
return s_instance;
}

void MQClientErrorContainer::setErr(std::string str) {
boost::lock_guard<boost::mutex> lock(this->mutex);
this->m_err = str;
}
void MQClientErrorContainer::setErr(std::string str) {
boost::lock_guard<boost::mutex> lock(this->mutex);
this->m_err = str;
}

std::string MQClientErrorContainer::getErr() {
boost::lock_guard<boost::mutex> lock(this->mutex);
return this->m_err;
}
std::string MQClientErrorContainer::getErr() {
boost::lock_guard<boost::mutex> lock(this->mutex);
return this->m_err;
}
} // namespace rocketmq
64 changes: 31 additions & 33 deletions src/common/MQClientErrorContainer.h
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
#pragma once
/*
* 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.
*/
* 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.
*/

#ifndef MQCLIENTERRORCONTAINER_H_INCLUDE
#define MQCLIENTERRORCONTAINER_H_INCLUDE
#include <string>
#include <exception>
#include <boost/thread/mutex.hpp>
#ifndef __MQCLIENTERRORCONTAINER_H_INCLUDE__
#define __MQCLIENTERRORCONTAINER_H_INCLUDE__
#include <boost/thread/lock_guard.hpp>
#include <boost/thread/mutex.hpp>
#include <exception>
#include <string>

namespace rocketmq {
class MQClientErrorContainer {

public:
static MQClientErrorContainer * instance();
class MQClientErrorContainer {
public:
static MQClientErrorContainer* instance();

void setErr(std::string str);
void setErr(std::string str);

std::string getErr();
std::string getErr();

private:
std::string m_err;
static MQClientErrorContainer * s_instance;
boost::mutex mutex;
};
}
private:
std::string m_err;
static MQClientErrorContainer* s_instance;
boost::mutex mutex;
};
} // namespace rocketmq

#endif
38 changes: 19 additions & 19 deletions src/extern/CErrorMessage.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
* 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.
*/
* 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.
*/

#include "CErrorMessage.h"
#include "CCommon.h"
@@ -22,11 +22,11 @@
#ifdef __cplusplus
extern "C" {
#endif
using namespace rocketmq;
using namespace rocketmq;

const char *GetLatestErrorMessage() {
return MQClientErrorContainer::instance()->getErr().c_str();
}
const char* GetLatestErrorMessage() {
return MQClientErrorContainer::instance()->getErr().c_str();
}

#ifdef __cplusplus
};
20 changes: 9 additions & 11 deletions src/extern/CProducer.cpp
Original file line number Diff line number Diff line change
@@ -16,20 +16,18 @@
*/

#include "CProducer.h"

#include <string.h>
#include <typeindex>

#include <string.h>
#include <typeinfo>
#include "AsyncCallback.h"
#include "CBatchMessage.h"
#include "CCommon.h"
#include "CMQException.h"
#include <string.h>
#include <typeinfo>
#include "MQClientErrorContainer.h"
#include "CMessage.h"
#include "CSendResult.h"
#include "DefaultMQProducer.h"
#include "MQClientErrorContainer.h"

#ifdef __cplusplus
extern "C" {
@@ -102,7 +100,7 @@ int StartProducer(CProducer* producer) {
try {
((DefaultMQProducer*)producer)->start();
} catch (exception& e) {
MQClientErrorContainer::instance()->setErr(string(e.what()));
MQClientErrorContainer::instance()->setErr(string(e.what()));
return PRODUCER_START_FAILED;
}
return OK;
@@ -158,7 +156,7 @@ int SendMessageSync(CProducer* producer, CMessage* msg, CSendResult* result) {
strncpy(result->msgId, sendResult.getMsgId().c_str(), MAX_MESSAGE_ID_LENGTH - 1);
result->msgId[MAX_MESSAGE_ID_LENGTH - 1] = 0;
} catch (exception& e) {
MQClientErrorContainer::instance()->setErr(string(e.what()));
MQClientErrorContainer::instance()->setErr(string(e.what()));
return PRODUCER_SEND_SYNC_FAILED;
}
return OK;
@@ -221,7 +219,7 @@ int SendMessageAsync(CProducer* producer,
delete cSendCallback;
cSendCallback = NULL;
}
MQClientErrorContainer::instance()->setErr(string(e.what()));
MQClientErrorContainer::instance()->setErr(string(e.what()));
return PRODUCER_SEND_ASYNC_FAILED;
}
return OK;
@@ -251,7 +249,7 @@ int SendMessageOnewayOrderly(CProducer* producer, CMessage* msg, QueueSelectorCa
SelectMessageQueue selectMessageQueue(selector);
defaultMQProducer->sendOneway(*message, &selectMessageQueue, arg);
} catch (exception& e) {
MQClientErrorContainer::instance()->setErr(string(e.what()));
MQClientErrorContainer::instance()->setErr(string(e.what()));
return PRODUCER_SEND_ONEWAY_FAILED;
}
return OK;
@@ -278,7 +276,7 @@ int SendMessageOrderlyAsync(CProducer* producer,
} catch (exception& e) {
printf("%s\n", e.what());
// std::count<<e.what( )<<std::endl;
MQClientErrorContainer::instance()->setErr(string(e.what()));
MQClientErrorContainer::instance()->setErr(string(e.what()));
return PRODUCER_SEND_ORDERLYASYNC_FAILED;
}
return OK;
@@ -305,7 +303,7 @@ int SendMessageOrderly(CProducer* producer,
strncpy(result->msgId, sendResult.getMsgId().c_str(), MAX_MESSAGE_ID_LENGTH - 1);
result->msgId[MAX_MESSAGE_ID_LENGTH - 1] = 0;
} catch (exception& e) {
MQClientErrorContainer::instance()->setErr(string(e.what()));
MQClientErrorContainer::instance()->setErr(string(e.what()));
return PRODUCER_SEND_ORDERLY_FAILED;
}
return OK;
12 changes: 6 additions & 6 deletions src/extern/CPullConsumer.cpp
Original file line number Diff line number Diff line change
@@ -15,10 +15,10 @@
* limitations under the License.
*/

#include "DefaultMQPullConsumer.h"
#include "CMessageExt.h"
#include "CPullConsumer.h"
#include "CCommon.h"
#include "CMessageExt.h"
#include "DefaultMQPullConsumer.h"
#include "MQClientErrorContainer.h"

using namespace rocketmq;
@@ -49,7 +49,7 @@ int StartPullConsumer(CPullConsumer* consumer) {
try {
((DefaultMQPullConsumer*)consumer)->start();
} catch (exception& e) {
MQClientErrorContainer::instance()->setErr(string(e.what()));
MQClientErrorContainer::instance()->setErr(string(e.what()));
return PULLCONSUMER_START_FAILED;
}
return OK;
@@ -152,7 +152,7 @@ int FetchSubscriptionMessageQueues(CPullConsumer* consumer, const char* topic, C
} catch (MQException& e) {
*size = 0;
*mqs = NULL;
MQClientErrorContainer::instance()->setErr(string(e.what()));
MQClientErrorContainer::instance()->setErr(string(e.what()));
return PULLCONSUMER_FETCH_MQ_FAILED;
}
return OK;
@@ -177,7 +177,7 @@ CPullResult Pull(CPullConsumer* consumer,
try {
cppPullResult = ((DefaultMQPullConsumer*)consumer)->pull(messageQueue, subExpression, offset, maxNums);
} catch (exception& e) {
MQClientErrorContainer::instance()->setErr(string(e.what()));
MQClientErrorContainer::instance()->setErr(string(e.what()));
cppPullResult.pullStatus = BROKER_TIMEOUT;
}

@@ -232,7 +232,7 @@ int ReleasePullResult(CPullResult pullResult) {
try {
delete ((PullResult*)pullResult.pData);
} catch (exception& e) {
MQClientErrorContainer::instance()->setErr(string(e.what()));
MQClientErrorContainer::instance()->setErr(string(e.what()));
return NULL_POINTER;
}
}
8 changes: 4 additions & 4 deletions src/extern/CPushConsumer.cpp
Original file line number Diff line number Diff line change
@@ -15,11 +15,11 @@
* limitations under the License.
*/

#include "DefaultMQPushConsumer.h"
#include "CMessageExt.h"
#include "CPushConsumer.h"
#include "CCommon.h"
#include <map>
#include "CCommon.h"
#include "CMessageExt.h"
#include "DefaultMQPushConsumer.h"
#include "MQClientErrorContainer.h"

using namespace rocketmq;
@@ -108,7 +108,7 @@ int StartPushConsumer(CPushConsumer* consumer) {
try {
((DefaultMQPushConsumer*)consumer)->start();
} catch (exception& e) {
MQClientErrorContainer::instance()->setErr(string(e.what()));
MQClientErrorContainer::instance()->setErr(string(e.what()));
return PUSHCONSUMER_START_FAILED;
}
return OK;
Loading