Add API allowing xAPPs to send alarm messages
[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 namespace xapp {
53
54 // ------------------------------------------------------------------------
55
56 class Message {
57         private:
58                 rmr_mbuf_t*     mbuf;                                   // the underlying RMR message buffer
59                 void*           mrc;                                    // message router context
60                 std::shared_ptr<char> psp;                      // shared pointer to the payload to give out
61
62         public:
63                 static const int        NO_CHANGE = -99;                        // indicates no change to a send/reply parameter
64                 static const int        NO_WHID = -1;                           // no wormhole id applies
65                 static const int        INVALID_MTYPE = -1;
66                 static const int        INVALID_STATUS = -1;
67                 static const int        INVALID_SUBID = -2;
68                 static const int        NO_SUBID = -1;                                  // not all messages have a subid
69
70                 static const int        RESPONSE = 0;                                   // send types
71                 static const int        MESSAGE = 1;
72                 static const int        WORMHOLE_MSG = 2;
73
74                 Message( rmr_mbuf_t* mbuf, void* mrc );         // builders
75                 Message( void* mrc, int payload_len );
76                 Message( const Message& soi );                          // copy cat
77                 Message& operator=( const Message& soi );       // copy operator
78                 Message( Message&& soi );                               // mover
79                 Message& operator=( Message&& soi );    // move operator
80                 ~Message();                                                                     // destroyer
81
82                 std::unique_ptr<unsigned char>  Copy_payload( );                // copy the payload; deletable smart pointer
83
84                 std::unique_ptr<unsigned char> Get_meid();                              // returns a copy of the meid bytes
85                 int Get_available_size();
86                 int     Get_len();
87                 int     Get_mtype();
88                 Msg_component Get_payload();
89                 std::unique_ptr<unsigned char>  Get_src();
90                 int     Get_state( );
91                 int     Get_subid();
92
93                 void Set_meid( std::shared_ptr<unsigned char> new_meid );
94                 void Set_mtype( int new_type );
95                 void Set_subid( int new_subid );
96                 void Set_len( int new_len );
97
98                 bool Reply( );
99                 bool Send( );
100                 bool Send( int mtype, int subid, int payload_len, unsigned char* payload, int stype, int whid );
101
102                 bool Send_msg( int mtype, int subid, int payload_len, std::shared_ptr<unsigned char> payload );
103                 bool Send_msg( int mtype, int subid, int payload_len, unsigned char* payload );
104                 bool Send_msg( int payload_len, std::shared_ptr<unsigned char> payload );
105                 bool Send_msg( int payload_len, unsigned char* payload );
106
107                 bool Send_response( int mtype, int subid, int payload_len, std::shared_ptr<unsigned char> response );
108                 bool Send_response( int mtype, int subid, int payload_len, unsigned char* response );
109                 bool Send_response( int payload_len, std::shared_ptr<unsigned char> response );
110                 bool Send_response( int payload_len, unsigned char* response );
111
112                 bool Wormhole_send( int whid, int mtype, int subid, int payload_len, std::shared_ptr<unsigned char> payload );
113 };
114
115 } // namespace
116
117 #endif