Handle case when no response is generated during request execution.
Change-Id: I2ffbcd520dcb910bae7ee342ab432fae457ef437
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd 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.
+ */
+/*
+ * @file NoResponseGeneratedException.h
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version 1.0
+ * @brief Implementation of NoResponseGeneratedException
+ */
+
+#ifndef SRC_COMMON_EXCEPTIONS_NORESPONSEGENERATEDEXCEPTION_H_
+#define SRC_COMMON_EXCEPTIONS_NORESPONSEGENERATEDEXCEPTION_H_
+
+#include "Exception.h"
+
+#include <exception>
+
+namespace Cynara {
+
+class NoResponseGeneratedException : public Exception {
+public:
+ NoResponseGeneratedException() = default;
+ virtual ~NoResponseGeneratedException() = default;
+};
+
+} /* namespace Cynara */
+
+#endif /* SRC_COMMON_EXCEPTIONS_NORESPONSEGENERATEDEXCEPTION_H_ */
Protocol();
virtual ~Protocol();
- virtual Request *extractRequestFromBuffer(BinaryQueue &bufferQueue) = 0;
+ virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue) = 0;
virtual void appendResponseToBuffer(CheckResponse &&response);
};
ProtocolAdmin::~ProtocolAdmin() {
}
-Request *ProtocolAdmin::extractRequestFromBuffer(BinaryQueue& bufferQueue) {
+RequestPtr ProtocolAdmin::extractRequestFromBuffer(BinaryQueue &bufferQueue) {
TODO_USE_ME(bufferQueue);
- return nullptr;
+ return RequestPtr(nullptr);
}
} // namespace Cynara
ProtocolAdmin();
virtual ~ProtocolAdmin();
- virtual Request *extractRequestFromBuffer(BinaryQueue &bufferQueue);
+ virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue);
};
} // namespace Cynara
ProtocolClient::~ProtocolClient() {
}
-Request *ProtocolClient::extractRequestFromBuffer(BinaryQueue& bufferQueue) {
+RequestPtr ProtocolClient::extractRequestFromBuffer(BinaryQueue &bufferQueue) {
TODO_USE_ME(bufferQueue);
- return nullptr;
+ return RequestPtr(nullptr);
}
} // namespace Cynara
ProtocolClient();
virtual ~ProtocolClient();
- virtual Request *extractRequestFromBuffer(BinaryQueue &bufferQueue);
+ virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue);
};
} // namespace Cynara
ProtocolSignal::~ProtocolSignal() {
}
-Request *ProtocolSignal::extractRequestFromBuffer(BinaryQueue& bufferQueue) {
+RequestPtr ProtocolSignal::extractRequestFromBuffer(BinaryQueue &bufferQueue) {
TODO_USE_ME(bufferQueue);
- return nullptr;
+ return RequestPtr(nullptr);
}
} // namespace Cynara
ProtocolSignal();
virtual ~ProtocolSignal();
- virtual Request *extractRequestFromBuffer(BinaryQueue &bufferQueue);
+ virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue);
};
} // namespace Cynara
#ifndef SRC_SERVICE_REQUEST_REQUEST_H_
#define SRC_SERVICE_REQUEST_REQUEST_H_
+#include <memory>
+
#include <logic/Logic.h>
namespace Cynara {
virtual void execute(Logic *logic, int sourceDesc) = 0;
};
+typedef std::shared_ptr<Request> RequestPtr;
+
} // namespace Cynara
#endif /* SRC_SERVICE_REQUEST_REQUEST_H_ */
m_readQueue.appendCopy(readbuffer.data(), readbuffer.size());
}
-Request *Descriptor::extractRequest(void) {
+RequestPtr Descriptor::extractRequest(void) {
return m_protocol->extractRequestFromBuffer(m_readQueue);
}
}
void pushReadBuffer(const RawBuffer &readbuffer);
- Request *extractRequest(void);
+ RequestPtr extractRequest(void);
RawBuffer &prepareWriteBuffer(void);
#include <common.h>
#include <exceptions/DescriptorNotExistsException.h>
#include <exceptions/InitException.h>
+#include <exceptions/NoResponseGeneratedException.h>
#include <exceptions/UnexpectedErrorException.h>
#include <logic/Logic.h>
desc.pushReadBuffer(readbuffer);
try {
- std::unique_ptr<Request> req(nullptr);
+ std::shared_ptr<Request> req(nullptr);
for (;;) {
- req.reset(desc.extractRequest());
- if (req)
+ req = desc.extractRequest();
+ if (!req)
break;
LOGD("request extracted");
- req->execute(Cynara::getLogic(), fd);
+ try {
+ req->execute(Cynara::getLogic(), fd);
- if (desc.hasDataToWrite())
+ if (desc.hasDataToWrite())
addWriteSocket(fd);
+ } catch (const NoResponseGeneratedException &ex) {
+ LOGD("no response generated");
+ }
}
} catch (const Exception &ex) {
LOGE("Error handling request <%s>. Closing socket", ex.what());