5034b77f9194d921125d78844713fc3a645c56df
[ric-app/mc.git] / sidecars / listener / test_rmr_em.c
1 // vim: ts=4 sw=4 noet:
2 /*
3 --------------------------------------------------------------------------------
4         Copyright (c) 2018-2019 AT&T Intellectual Property.
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10            http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 --------------------------------------------------------------------------------
18 */
19
20 /*
21         Mnemonic:       test_rmr_em.c.
22         Abstract:       Emulates some RMR functions (message receipt mostly)
23                                 so that we can unit test.
24
25                                 This file should be included by the test programme BEFORE
26                                 any module which uses RMR functions is included
27
28         Date:           10 December 2019
29         Author:         E. Scott Daniels
30 */
31
32 #include <rmr/rmr.h>
33
34 #define rmr_torcv_msg RMR_torcv_msg
35
36 extern rmr_mbuf_t* RMR_torcv_msg( void* ctx, rmr_mbuf_t* old_msg, int ms_to ) {
37         static int timeout = 0;
38
39         if( old_msg == NULL ) {
40                 old_msg = rmr_alloc_msg( ctx, 256 );
41                 if( old_msg == NULL ) {
42                         return NULL;
43                 }
44         }
45
46         timeout = ! timeout;                                    // every other message results in a timeout
47         if( timeout ) {
48                 old_msg->state = RMR_ERR_TIMEOUT;
49                 return old_msg; 
50         }
51
52
53         snprintf( old_msg->payload, 100, "DUMMY MESSAGE" );
54         old_msg->mtype = 100;
55         old_msg->len = strlen( old_msg->payload );
56         old_msg->sub_id = -1;
57         old_msg->state = 0;
58
59         return old_msg;
60 }