0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-30 02:16:55 +08:00

98 lines
2.3 KiB
C
Raw Normal View History

2016-09-18 19:11:22 +03:00
#ifndef EASY_NET_H
#define EASY_NET_H
#include <stdint.h>
namespace profiler {
namespace net {
const char* DAFAULT_ADDRESS = "tcp://127.0.0.1:28077";
const uint32_t EASY_MESSAGE_SIGN = 20160909;
#pragma pack(push,1)
enum MessageType : uint8_t
{
MESSAGE_TYPE_ZERO = 0,
2016-09-18 19:11:22 +03:00
MESSAGE_TYPE_REQUEST_START_CAPTURE,
MESSAGE_TYPE_REPLY_START_CAPTURING,
MESSAGE_TYPE_REQUEST_STOP_CAPTURE,
2016-09-18 19:11:22 +03:00
MESSAGE_TYPE_REPLY_BLOCKS,
MESSAGE_TYPE_REPLY_BLOCKS_END,
MESSAGE_TYPE_ACCEPTED_CONNECTION,
MESSAGE_TYPE_REQUEST_BLOCKS_DESCRIPTION,
MESSAGE_TYPE_REPLY_BLOCKS_DESCRIPTION,
MESSAGE_TYPE_REPLY_BLOCKS_DESCRIPTION_END,
MESSAGE_TYPE_EDIT_BLOCK_STATUS,
MESSAGE_TYPE_EVENT_TRACING_STATUS,
MESSAGE_TYPE_EVENT_TRACING_PRIORITY,
2016-09-18 19:11:22 +03:00
};
struct Message
{
uint32_t magic_number = EASY_MESSAGE_SIGN;
MessageType type = MESSAGE_TYPE_ZERO;
bool isEasyNetMessage() const
{
return EASY_MESSAGE_SIGN == magic_number;
}
Message() = default;
Message(MessageType _t):type(_t){}
};
struct DataMessage : public Message {
uint32_t size = 0; // bytes
DataMessage(MessageType _t = MESSAGE_TYPE_REPLY_BLOCKS) : Message(_t) {}
DataMessage(uint32_t _s, MessageType _t = MESSAGE_TYPE_REPLY_BLOCKS) : Message(_t), size(_s) {}
const char* data() const { return reinterpret_cast<const char*>(this) + sizeof(DataMessage); }
};
struct BlockStatusMessage : public Message {
uint32_t id;
uint8_t status;
BlockStatusMessage(uint32_t _id, uint8_t _status) : Message(MESSAGE_TYPE_EDIT_BLOCK_STATUS), id(_id), status(_status) { }
private:
BlockStatusMessage() = delete;
};
struct EasyProfilerStatus : public Message
{
bool isProfilerEnabled;
bool isEventTracingEnabled;
bool isLowPriorityEventTracing;
EasyProfilerStatus(bool _enabled, bool _ETenabled, bool _ETlowp)
: Message(MESSAGE_TYPE_ACCEPTED_CONNECTION)
, isProfilerEnabled(_enabled)
, isEventTracingEnabled(_ETenabled)
, isLowPriorityEventTracing(_ETlowp)
{
}
private:
EasyProfilerStatus() = delete;
};
struct BoolMessage : public Message {
bool flag = false;
BoolMessage(MessageType _t, bool _flag = false) : Message(_t), flag(_flag) { }
BoolMessage() = default;
2016-09-18 19:11:22 +03:00
};
#pragma pack(pop)
}//net
}//profiler
#endif // EASY_NET_H