X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=inline;f=RIC-E2-TERMINATION%2FmapWrapper.h;fp=RIC-E2-TERMINATION%2FmapWrapper.h;h=fa997da503652caa9e27c851adb3b6f5546f8a2e;hb=1a79bdfd453f4ae8e07074a4cc6669672c7ca2f7;hp=0000000000000000000000000000000000000000;hpb=59f84608ec15c016958a6e0e0ddd813f376c0925;p=ric-plt%2Fe2.git diff --git a/RIC-E2-TERMINATION/mapWrapper.h b/RIC-E2-TERMINATION/mapWrapper.h new file mode 100644 index 0000000..fa997da --- /dev/null +++ b/RIC-E2-TERMINATION/mapWrapper.h @@ -0,0 +1,77 @@ +/* + * Copyright 2019 AT&T Intellectual Property + * Copyright 2019 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// Created by adi ENZEL on 8/28/19. +// + +#ifndef E2_MAPWRAPPER_H +#define E2_MAPWRAPPER_H + +#include +#include +#include +#include +#include +#include + +using namespace std; + +class mapWrapper { +public: + void *find(char *key) { + shared_lock read(fence); + if (mdclog_level_get() >= MDCLOG_DEBUG) { + + } + auto entry = keyMap.find(key); + if (entry == keyMap.end()) { + return nullptr; + } + return entry->second; + } + + void setkey(char *key, void *val) { + unique_lock write(fence); + keyMap[key] = val; + } + + void *erase(char *key) { + unique_lock write(fence); + return (void *)keyMap.erase(key); + } + + void clear() { + unique_lock write(fence); + keyMap.clear(); + } + + void getKeys(vector &v) { + shared_lock read(fence); + for (auto const &e : keyMap) { + v.emplace_back((char *)e.first.c_str()); + } + } + + + +private: + std::unordered_map keyMap; + shared_timed_mutex fence; + +}; +#endif //E2_MAPWRAPPER_H