blob: b7237b574f7f9841f248e3218d134796989052c5 [file] [log] [blame]
San Mehatdc266072009-05-06 11:16:52 -07001/*
2 * Copyright (C) 2008 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#include <stdlib.h>
17
18#define LOG_TAG "ScanResult"
19#include <cutils/log.h>
20
21#include "ScanResult.h"
22
23ScanResult::ScanResult() {
24}
25
26ScanResult::ScanResult(char *rawResult) {
27 char *tok, *next = NULL;
28
29 if (!(tok = strtok_r(rawResult, "\t", &next)))
30 goto out_bad;
31 mBssid = strdup(tok);
32
33 if (!(tok = strtok_r(NULL, "\t", &next)))
34 goto out_bad;
35 mFreq = atoi(tok);
36
37 if (!(tok = strtok_r(NULL, "\t", &next)))
38 goto out_bad;
39 mLevel = atoi(tok);
40
41 if (!(tok = strtok_r(rawResult, "\t", &next)))
42 goto out_bad;
43 mFlags = strdup(tok);
44
45 if (!(tok = strtok_r(rawResult, "\t", &next)))
46 goto out_bad;
47 mSsid = strdup(tok);
48
49 return;
50
51 out_bad:
52 LOGW("Malformatted scan result (%s)", rawResult);
53}
54
55ScanResult::~ScanResult() {
56 if (mBssid)
57 free(mBssid);
58 if (mFlags)
59 free(mFlags);
60 if (mSsid)
61 free(mSsid);
62}
63
64ScanResult *ScanResult::clone() {
65 ScanResult *r = new ScanResult();
66
67 r->mBssid = strdup(mBssid);
68 r->mFreq = mFreq;
69 r->mLevel = mLevel;
70 r->mFlags = strdup(mFlags);
71 r->mSsid = strdup(mSsid);
72
73 return r;
74}