622348c4052e59f19ac0235b37efce268cb2d572
[ric-app/bouncer.git] / Bouncer / src / xapp-utils / xapp_sdl.cc
1 /*
2 ==================================================================================
3
4         Copyright (c) 2019-2020 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  * xapp_sdl.cc
22  *
23  *  Created on: Mar, 2020
24  *  Author: Shraboni Jana
25  */
26 #include "xapp_sdl.hpp"
27 /*need to work on the SDL FLow. Currently data hardcoded.
28 An xApp can use the SDL for two things:
29 - persisting state for itself (in case it fails and recovers)
30 - making information available for other xApps. The xApp would typically write using SDL directly.
31 - The consumer of the data could also use SDL directly or use an access library like in the case of the R-NIB.
32 */
33 /*bool XappSDL::set_data(shareddatalayer::SyncStorage *sdl){
34         try{
35                 //connecting to the Redis and generating a random key for namespace "bouncer-xapp"
36                 mdclog_write(MDCLOG_INFO,  "IN SDL Set Data", __FILE__, __LINE__);
37                 DataMap dmap;
38                 char key[4]="abc";
39                 std::cout << "KEY: "<< key << std::endl;
40                 Key k = key;
41                 Data d;
42                 uint8_t num = 101;
43                 d.push_back(num);
44                 dmap.insert({k,d});
45                 Namespace ns(sdl_namespace);
46                 sdl->set(ns, dmap);
47         }
48         catch(...){
49                 mdclog_write(MDCLOG_ERR,  "SDL Error in Set Data for Namespace=%s",sdl_namespace);
50                 return false;
51         }
52         return true;
53 }
54
55 void XappSDL::get_data(shareddatalayer::SyncStorage *sdl){
56         Namespace ns(sdl_namespace);
57         DataMap dmap;
58         std::string prefix="";
59         Keys K = sdl->findKeys(ns, prefix);     // just the prefix
60         DataMap Dk = sdl->get(ns, K);
61         for(auto si=K.begin();si!=K.end();++si){
62                 std::vector<uint8_t> val_v = Dk[(*si)]; // 4 lines to unpack a string
63                 char val[val_v.size()+1];                               // from Data
64                 int i;
65                 for(i=0;i<val_v.size();++i) val[i] = (char)(val_v[i]);
66                 val[i]='\0';
67                 printf("KEYS and Values %s = %s\n",(*si).c_str(), val);
68         }
69
70         mdclog_write(MDCLOG_INFO,  "IN SDL Get Data", __FILE__, __LINE__);
71 }*/