1 /** 2 Lightweight profiler library for c++ 3 Copyright(C) 2016-2017 Sergey Yagovtsev, Victor Zarubkin 4 5 Licensed under either of 6 * MIT license (LICENSE.MIT or http://opensource.org/licenses/MIT) 7 * Apache License, Version 2.0, (LICENSE.APACHE or http://www.apache.org/licenses/LICENSE-2.0) 8 at your option. 9 10 The MIT License 11 Permission is hereby granted, free of charge, to any person obtaining a copy 12 of this software and associated documentation files (the "Software"), to deal 13 in the Software without restriction, including without limitation the rights 14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 15 of the Software, and to permit persons to whom the Software is furnished 16 to do so, subject to the following conditions: 17 18 The above copyright notice and this permission notice shall be included in all 19 copies or substantial portions of the Software. 20 21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 23 PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 26 USE OR OTHER DEALINGS IN THE SOFTWARE. 27 28 29 The Apache License, Version 2.0 (the "License"); 30 You may not use this file except in compliance with the License. 31 You may obtain a copy of the License at 32 33 http://www.apache.org/licenses/LICENSE-2.0 34 35 Unless required by applicable law or agreed to in writing, software 36 distributed under the License is distributed on an "AS IS" BASIS, 37 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 38 See the License for the specific language governing permissions and 39 limitations under the License. 40 41 **/ 42 43 #ifndef EASY_NET_H 44 #define EASY_NET_H 45 46 #include <easy/details/easy_compiler_support.h> 47 #include <stdint.h> 48 49 namespace profiler { namespace net { 50 51 EASY_CONSTEXPR uint32_t EASY_MESSAGE_SIGN = 20160909; 52 53 #pragma pack(push,1) 54 55 enum class MessageType : uint8_t 56 { 57 Undefined = 0, 58 59 Request_Start_Capture, 60 Reply_Capturing_Started, 61 Request_Stop_Capture, 62 63 Reply_Blocks, 64 Reply_Blocks_End, 65 66 Connection_Accepted, 67 68 Request_Blocks_Description, 69 Reply_Blocks_Description, 70 Reply_Blocks_Description_End, 71 72 Change_Block_Status, 73 Change_Event_Tracing_Status, 74 Change_Event_Tracing_Priority, 75 76 Ping, 77 78 Request_MainThread_FPS, 79 Reply_MainThread_FPS, 80 }; 81 82 struct Message 83 { 84 uint32_t magic_number = EASY_MESSAGE_SIGN; 85 MessageType type = MessageType::Undefined; 86 isEasyNetMessageMessage87 bool isEasyNetMessage() const EASY_NOEXCEPT { 88 return EASY_MESSAGE_SIGN == magic_number; 89 } 90 MessageMessage91 explicit Message(MessageType _t) EASY_NOEXCEPT : type(_t) { } 92 93 Message() = default; 94 }; 95 96 struct DataMessage : public Message 97 { 98 uint32_t size = 0; // bytes 99 MessageDataMessage100 explicit DataMessage(MessageType _t = MessageType::Reply_Blocks) : Message(_t) {} MessageDataMessage101 explicit DataMessage(uint32_t _s, MessageType _t = MessageType::Reply_Blocks) : Message(_t), size(_s) {} 102 dataDataMessage103 const char* data() const { return reinterpret_cast<const char*>(this) + sizeof(DataMessage); } 104 }; 105 106 struct BlockStatusMessage : public Message 107 { 108 uint32_t id; 109 uint8_t status; 110 BlockStatusMessageBlockStatusMessage111 explicit BlockStatusMessage(uint32_t _id, uint8_t _status) 112 : Message(MessageType::Change_Block_Status), id(_id), status(_status) { } 113 114 BlockStatusMessage() = delete; 115 }; 116 117 struct EasyProfilerStatus : public Message 118 { 119 bool isProfilerEnabled; 120 bool isEventTracingEnabled; 121 bool isLowPriorityEventTracing; 122 EasyProfilerStatusEasyProfilerStatus123 explicit EasyProfilerStatus(bool _enabled, bool _ETenabled, bool _ETlowp) 124 : Message(MessageType::Connection_Accepted) 125 , isProfilerEnabled(_enabled) 126 , isEventTracingEnabled(_ETenabled) 127 , isLowPriorityEventTracing(_ETlowp) 128 { 129 } 130 131 EasyProfilerStatus() = delete; 132 }; 133 134 struct BoolMessage : public Message 135 { 136 bool flag = false; 137 138 explicit BoolMessage(MessageType _t, bool _flag = false) MessageBoolMessage139 : Message(_t), flag(_flag) { } 140 141 BoolMessage() = default; 142 }; 143 144 struct TimestampMessage : public Message 145 { 146 uint32_t maxValue = 0; 147 uint32_t avgValue = 0; 148 TimestampMessageTimestampMessage149 explicit TimestampMessage(MessageType _t, uint32_t _maxValue, uint32_t _avgValue) 150 : Message(_t), maxValue(_maxValue), avgValue(_avgValue) { } 151 152 TimestampMessage() = default; 153 }; 154 155 #pragma pack(pop) 156 157 }//net 158 159 }//profiler 160 161 #endif // EASY_NET_H 162