UidRange.h revision 9f9aae9102f62f5f96ccec670170ee1fb262ef09
1/*
2 * Copyright (C) 2016 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#ifndef NETD_SERVER_ANDROID_NET_UID_RANGE_H
18#define NETD_SERVER_ANDROID_NET_UID_RANGE_H
19
20#include <binder/Parcelable.h>
21
22namespace android {
23
24namespace net {
25
26/*
27 * C++ implementation of UidRange, a contiguous range of UIDs.
28 */
29class UidRange : public Parcelable {
30public:
31    UidRange() = default;
32    virtual ~UidRange() = default;
33    UidRange(const UidRange& range) = default;
34    UidRange(int32_t start, int32_t stop);
35
36    status_t writeToParcel(Parcel* parcel) const override;
37    status_t readFromParcel(const Parcel* parcel) override;
38
39    /*
40     * Setters for UidRange start and stop UIDs.
41     */
42    void setStart(int32_t uid);
43    void setStop(int32_t uid);
44
45    /*
46     * Getters for UidRange start and stop UIDs.
47     */
48    int32_t getStart() const;
49    int32_t getStop() const;
50
51    friend bool operator<(const UidRange& lhs, const UidRange& rhs) {
52        return lhs.mStart != rhs.mStart ? (lhs.mStart < rhs.mStart) : (lhs.mStop < rhs.mStop);
53    }
54
55    friend bool operator==(const UidRange& lhs, const UidRange& rhs) {
56        return (lhs.mStart == rhs.mStart && lhs.mStop == rhs.mStop);
57    }
58
59    friend bool operator!=(const UidRange& lhs, const UidRange& rhs) {
60        return !(lhs == rhs);
61    }
62
63private:
64    int32_t mStart = -1;
65    int32_t mStop = -1;
66};
67
68}  // namespace net
69
70}  // namespace android
71
72#endif  // NETD_SERVER_ANDROID_NET_UID_RANGE_H
73