76fea798720736ee87341ddb4c438dc17cc3a2ad
[ric-plt/lib/rmr.git] / src / rmr / si / src / rtc_si_static.c
1 // : vi ts=4 sw=4 noet :
2 /*
3 ==================================================================================
4         Copyright (c) 2019-2020 Nokia
5         Copyright (c) 2018-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:       rtc_si_static.c
23         Abstract:       This is a test module to allow the route table to be read
24                                 from a static spot and NOT to attempt to listen for updates
25                                 from some outside source.
26
27         Author:         E. Scott Daniels
28         Date:           18 October 2019
29 */
30
31 #ifndef _rtc_si_staic_c
32 #define _rtc_si_staic_c
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <netdb.h>
37 #include <errno.h>
38 #include <string.h>
39 #include <errno.h>
40 #include <fcntl.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <unistd.h>
44
45 /*
46         Loop forever (assuming we're running in a pthread reading the static table
47         every minute or so.
48 */
49 static void* rtc_file( void* vctx ) {
50         uta_ctx_t*      ctx;                                    // context user has -- where we pin the route table
51         char*   eptr;
52         int             vfd = -1;                                       // verbose file des if we have one
53         int             vlevel = 0;                                     // how chatty we should be 0== no nattering allowed
54         char    wbuf[256];
55
56
57         if( (ctx = (uta_ctx_t *) vctx) == NULL ) {
58                 fprintf( stderr, "[CRI] rmr_rtc: internal mishap: context passed in was nil\n" );
59                 return NULL;
60         }
61
62         if( (eptr = getenv( ENV_VERBOSE_FILE )) != NULL ) {
63                 vfd = open( eptr, O_RDONLY );
64         }
65
66         while( 1 ) {
67                 if( vfd >= 0 ) {
68                         wbuf[0] = 0;
69                         lseek( vfd, 0, 0 );
70                         read( vfd, wbuf, 10 );
71                         vlevel = atoi( wbuf );
72                 }                
73         
74                 read_static_rt( ctx, vlevel );                                          // seed the route table if one provided
75
76                 sleep( 60 );
77         }
78
79 }
80 #endif