2 ==================================================================================
4 Copyright (c) 2019-2020 AT&T Intellectual Property.
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
10 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
23 * Created on: Mar, 2020
24 * Author: Shraboni Jana
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.
33 bool XappSDL::set_data(shareddatalayer::SyncStorage *sdl){
35 //connecting to the Redis and generating a random key for namespace "hwxapp"
36 mdclog_write(MDCLOG_INFO, "IN SDL Set Data", __FILE__, __LINE__);
39 std::cout << "KEY: "<< key << std::endl;
45 Namespace ns(sdl_namespace);
49 mdclog_write(MDCLOG_ERR, "SDL Error in Set Data for Namespace=%s",sdl_namespace);
55 void XappSDL::get_data(shareddatalayer::SyncStorage *sdl){
56 Namespace ns(sdl_namespace);
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
65 for(i=0;i<val_v.size();++i) val[i] = (char)(val_v[i]);
67 printf("KEYS and Values %s = %s\n",(*si).c_str(), val);
70 mdclog_write(MDCLOG_INFO, "IN SDL Get Data", __FILE__, __LINE__);