0db0927f6baa851031e9cd5efd29098247c35bfb
[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( const Message& soi );                          // copy cat
73                 Message& operator=( const Message& soi );       // copy operator
74                 Message( Message&& soi );                               // mover
75                 Message& operator=( Message&& soi );    // move operator
76                 ~Message();                                                                     // destroyer
77
78                 std::unique_ptr<unsigned char>  Copy_payload( );                // copy the payload; deletable smart pointer
79
80                 std::unique_ptr<unsigned char> Get_meid();                              // returns a copy of the meid bytes
81                 int Get_available_size();
82                 int     Get_len();
83                 int     Get_mtype();
84                 Msg_component Get_payload();
85                 std::unique_ptr<unsigned char>  Get_src();
86                 int     Get_state( );
87                 int     Get_subid();
88
89                 void Set_meid( std::shared_ptr<unsigned char> new_meid );
90                 void Set_mtype( int new_type );
91                 void Set_subid( int new_subid );
92                 void Set_len( int new_len );
93
94                 bool Reply( );
95                 bool Send( );
96                 bool Send( int mtype, int subid, int payload_len, unsigned char* payload, int stype );
97
98                 bool Send_msg( int mtype, int subid, int payload_len, std::shared_ptr<unsigned char> payload );
99                 bool Send_msg( int mtype, int subid, int payload_len, unsigned char* payload );
100                 bool Send_msg( int payload_len, std::shared_ptr<unsigned char> payload );
101                 bool Send_msg( int payload_len, unsigned char* payload );
102
103                 bool Send_response( int mtype, int subid, int payload_len, std::shared_ptr<unsigned char> response );
104                 bool Send_response( int mtype, int subid, int payload_len, unsigned char* response );
105                 bool Send_response( int payload_len, std::shared_ptr<unsigned char> response );
106                 bool Send_response( int payload_len, unsigned char* response );
107 };
108
109
110 #endif