Add unit tests and changes related
[ric-plt/xapp-frame-cpp.git] / src / messaging / message.hpp
1 // vi: ts=4 sw=4 noet:
2 /*
3 ==================================================================================
4         Copyright (c) 2020 Nokia
5         Copyright (c) 2020 AT&T Intellectual Property.
6
7    Licensed under the Apache License, Version 2.0 (the "License");
8    you may not use this file except in compliance with the License.
9    You may obtain a copy of the License at
10
11        http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18 ==================================================================================
19 */
20
21 /*
22         Mnemonic:       message.hpp
23         Abstract:       Headers for the message class.
24                                 This class provides an interface to the user application
25                                 when information from the message is needed.
26
27         Date:           10 March 2020
28         Author:         E. Scott Daniels
29 */
30
31 #ifndef _MESSAGE_HPP
32 #define _MESSAGE_HPP
33
34
35 #include <iostream>
36 #include <string>
37
38 #include <rmr/rmr.h>
39
40 #include "msg_component.hpp"
41 #include "callback.hpp"
42 #include "default_cb.hpp"
43
44 #ifndef RMR_NO_CLONE
45         #define RMR_NO_CLONE    0
46         #define RMR_NO_COPY     0
47         #define RMR_CLONE       1
48         #define RMR_COPY        1
49 #endif
50
51
52 // ------------------------------------------------------------------------
53
54 class Message {
55         private:
56                 rmr_mbuf_t*     mbuf;                                   // the underlying RMR message buffer
57                 void*           mrc;                                    // message router context
58                 std::shared_ptr<char> psp;                      // shared pointer to the payload to give out
59
60         public:
61                 static const int        NO_CHANGE = -99;                        // indicates no change to a send/reply parameter
62                 static const int        INVALID_MTYPE = -1;
63                 static const int        INVALID_STATUS = -1;
64                 static const int        INVALID_SUBID = -2;
65                 static const int        NO_SUBID = -1;                                  // not all messages have a subid
66
67                 static const int        RESPONSE = 0;                                   // send types
68                 static const int        MESSAGE = 1;
69
70                 Message( rmr_mbuf_t* mbuf, void* mrc );         // builders
71                 Message( void* mrc, int payload_len );
72                 ~Message();                                                                     // destroyer
73
74                 std::unique_ptr<unsigned char>  Copy_payload( );                // copy the payload; deletable smart pointer
75
76                 std::unique_ptr<unsigned char> Get_meid();                              // returns a copy of the meid bytes
77                 int Get_available_size();
78                 int     Get_len();
79                 int     Get_mtype();
80                 Msg_component Get_payload();
81                 std::unique_ptr<unsigned char>  Get_src();
82                 int     Get_state( );
83                 int     Get_subid();
84
85                 void Set_meid( std::shared_ptr<unsigned char> new_meid );
86                 void Set_mtype( int new_type );
87                 void Set_subid( int new_subid );
88                 void Set_len( int new_len );
89
90                 bool Reply( );
91                 bool Send( );
92                 bool Send( int mtype, int subid, int payload_len, unsigned char* payload, int stype );
93
94                 bool Send_msg( int mtype, int subid, int payload_len, std::shared_ptr<unsigned char> payload );
95                 bool Send_msg( int mtype, int subid, int payload_len, unsigned char* payload );
96                 bool Send_msg( int payload_len, std::shared_ptr<unsigned char> payload );
97                 bool Send_msg( int payload_len, unsigned char* payload );
98
99                 bool Send_response( int mtype, int subid, int payload_len, std::shared_ptr<unsigned char> response );
100                 bool Send_response( int mtype, int subid, int payload_len, unsigned char* response );
101                 bool Send_response( int payload_len, std::shared_ptr<unsigned char> response );
102                 bool Send_response( int payload_len, unsigned char* response );
103 };
104
105
106 #endif