blob: 98c0625afb2c07c13067a0a3d9652bb078830385 [file] [log] [blame]
Jorge E. Moreirad6c129e2018-01-05 14:52:21 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <arpa/inet.h>
18
19#include <mutex>
20
21#include "common/vsoc/lib/ril_region_view.h"
22
23namespace vsoc {
24namespace ril {
25
26// TODO(jemoreira): use the general region singleton implementation when ready
27#if defined(CUTTLEFISH_HOST)
28RilRegionView* RilRegionView::GetInstance(const char* domain) {
29#else
30RilRegionView* RilRegionView::GetInstance() {
31#endif
32 static std::mutex m;
33 static RilRegionView* region;
34
35 std::lock_guard<std::mutex> lock(m);
36 if (!region) {
37 region = new RilRegionView();
38
39#if defined(CUTTLEFISH_HOST)
40 if (!region->Open(domain)) {
41#else
42 if (!region->Open()) {
43#endif
44 delete region;
45 region = nullptr;
46 }
47 }
48 return region;
49}
50
51const char* RilRegionView::address_and_prefix_length() const {
52 static char buffer[sizeof(data().ipaddr) + 3]{}; // <ipaddr>/dd
53 if (buffer[0] == '\0') {
54 snprintf(buffer, sizeof(buffer), "%s/%d", data().ipaddr, data().prefixlen);
55 }
56 return &buffer[0];
57}
58
59} // namespace ril
60} // namespace vsoc