#include <memory.h>
+#include "utils/logger.h"
+
#include "connection_handler/connection_handler_impl.h"
#include "config_profile/profile.h"
namespace protocol_handler {
-#ifdef ENABLE_LOG
-log4cxx::LoggerPtr ProtocolHandlerImpl::logger_ = log4cxx::LoggerPtr(
- log4cxx::Logger::getLogger("ProtocolHandler"));
-#endif // ENABLE_LOG
-
+CREATE_LOGGERPTR_GLOBAL(logger_, "ProtocolHandler")
/**
* Function return packet data as std::string.
raw_ford_messages_from_mobile_("MessagesFromMobileAppHandler", this,
threads::ThreadOptions(kStackSize)),
raw_ford_messages_to_mobile_("MessagesToMobileAppHandler", this,
- threads::ThreadOptions(kStackSize)) {
+ threads::ThreadOptions(kStackSize)),
+ metric_observer_(NULL) {
LOG4CXX_TRACE_ENTER(logger_);
LOG4CXX_TRACE_EXIT(logger_);
return RESULT_OK;
}
+void ProtocolHandlerImpl::SendHeartBeat(int32_t connection_id,
+ uint8_t session_id) {
+ LOG4CXX_TRACE_ENTER(logger_);
+
+ ProtocolFramePtr ptr(new protocol_handler::ProtocolPacket(connection_id,
+ PROTOCOL_VERSION_3, COMPRESS_OFF, FRAME_TYPE_CONTROL,
+ SERVICE_TYPE_ZERO, FRAME_DATA_HEART_BEAT, session_id,
+ 0, 0));
+
+ raw_ford_messages_to_mobile_.PostMessage(
+ impl::RawFordMessageToMobile(ptr, false));
+
+ LOG4CXX_TRACE_EXIT(logger_);
+}
+
void ProtocolHandlerImpl::SendMessageToMobileApp(const RawMessagePtr& message,
bool final_message) {
LOG4CXX_TRACE_ENTER(logger_);
void ProtocolHandlerImpl::OnTMMessageReceived(const RawMessagePtr tm_message) {
LOG4CXX_TRACE_ENTER(logger_);
- connection_handler::ConnectionHandlerImpl* connection_handler =
- connection_handler::ConnectionHandlerImpl::instance();
- // Connection handler should be accessed from TM thread only
- connection_handler->KeepConnectionAlive(tm_message->connection_key());
if (tm_message) {
LOG4CXX_INFO_EXT(
for (std::vector<ProtocolFramePtr>::const_iterator it =
protocol_frames.begin();
it != protocol_frames.end(); ++it) {
- raw_ford_messages_from_mobile_.PostMessage(
- impl::RawFordMessageFromMobile(*it));
+ impl::RawFordMessageFromMobile msg(*it);
+ if (metric_observer_) {
+ metric_observer_->StartMessageProcess(msg->message_id());
+ }
+ raw_ford_messages_from_mobile_.PostMessage(msg);
}
LOG4CXX_TRACE_EXIT(logger_);
}
RESULT_CODE ProtocolHandlerImpl::HandleMessage(ConnectionID connection_id,
const ProtocolFramePtr& packet) {
LOG4CXX_TRACE_ENTER(logger_);
-
switch (packet->frame_type()) {
case FRAME_TYPE_CONTROL: {
LOG4CXX_INFO(logger_, "handleMessage(1) - case FRAME_TYPE_CONTROL");
RawMessagePtr raw_message(
new RawMessage(connection_key, packet->protocol_version(), packet->data(),
packet->data_size(), packet->service_type()));
-
+ if (metric_observer_) {
+ PHMetricObserver::MessageMetric* metric = new PHMetricObserver::MessageMetric();
+ metric->message_id = packet->message_id();
+ metric->connection_key = connection_key;
+ metric->raw_msg = raw_message;
+ metric_observer_->EndMessageProcess(metric);
+ }
NotifySubscribers(raw_message);
break;
}
RESULT_CODE ProtocolHandlerImpl::HandleMultiFrameMessage(
ConnectionID connection_id, const ProtocolFramePtr& packet) {
LOG4CXX_TRACE_ENTER(logger_);
-
if (!session_observer_) {
LOG4CXX_ERROR(logger_, "No ISessionObserver set.");
}
ProtocolPacket* completePacket = it->second.get();
- RawMessage* rawMessage = new RawMessage(
+ RawMessagePtr rawMessage (new RawMessage(
key, completePacket->protocol_version(), completePacket->data(),
- completePacket->total_data_bytes(), completePacket->service_type());
-
+ completePacket->total_data_bytes(), completePacket->service_type()));
+ if (metric_observer_) {
+ PHMetricObserver::MessageMetric* metric = new PHMetricObserver::MessageMetric();
+ metric->raw_msg = rawMessage;
+ metric_observer_->EndMessageProcess(metric);
+ }
NotifySubscribers(rawMessage);
incomplete_multi_frame_messages_.erase(it);
RESULT_CODE ProtocolHandlerImpl::HandleControlMessage(
ConnectionID connection_id, const ProtocolFramePtr& packet) {
+
if (!session_observer_) {
LOG4CXX_ERROR(logger_, "ISessionObserver is not set.");
"Received heart beat for connection " << connection_id);
return HandleControlMessageHeartBeat(connection_id, *(packet.get()));
}
+ case FRAME_DATA_HEART_BEAT_ACK: {
+ LOG4CXX_INFO(logger_, "Received heart beat ack from mobile app"
+ " for connection " << connection_id);
+ }
default:
LOG4CXX_WARN(
logger_,
static_cast<int>(packet.protocol_version()));
int32_t session_id = session_observer_->OnSessionStartedCallback(
- connection_id, packet.session_id(),
+ connection_id, packet.session_id(), packet.protocol_version(),
ServiceTypeFromByte(packet.service_type()));
if (-1 != session_id) {
const impl::RawFordMessageFromMobile& message) {
LOG4CXX_TRACE_ENTER(logger_);
+ connection_handler::ConnectionHandlerImpl* connection_handler =
+ connection_handler::ConnectionHandlerImpl::instance();
+ connection_handler->KeepConnectionAlive(message->connection_key(),
+ message->session_id());
+
if (((0 != message->data()) && (0 != message->data_size())) ||
FRAME_TYPE_CONTROL == message->frame_type() ||
FRAME_TYPE_FIRST == message->frame_type()) {
session_id, 0, number_of_frames));
raw_ford_messages_to_mobile_.PostMessage(
- impl::RawFordMessageToMobile(ptr, false));
+ impl::RawFordMessageToMobile(ptr, false));
+}
+
+void ProtocolHandlerImpl::SetTimeMetricObserver(PHMetricObserver* observer) {
+ metric_observer_ = observer;
}
std::string ConvertPacketDataToString(const uint8_t* data,