Home | History | Annotate | Download | only in net
      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 
     22 namespace android {
     23 
     24 namespace net {
     25 
     26 /*
     27  * C++ implementation of UidRange, a contiguous range of UIDs.
     28  */
     29 class UidRange : public Parcelable {
     30 public:
     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     /**
     52      * Additional functions.
     53      */
     54     uint32_t length() const;
     55 
     56 
     57     /**
     58      * Operators and comparators.
     59      */
     60     friend bool operator<(const UidRange& lhs, const UidRange& rhs) {
     61         return lhs.mStart != rhs.mStart ? (lhs.mStart < rhs.mStart) : (lhs.mStop < rhs.mStop);
     62     }
     63 
     64     friend bool operator==(const UidRange& lhs, const UidRange& rhs) {
     65         return (lhs.mStart == rhs.mStart && lhs.mStop == rhs.mStop);
     66     }
     67 
     68     friend bool operator!=(const UidRange& lhs, const UidRange& rhs) {
     69         return !(lhs == rhs);
     70     }
     71 
     72 private:
     73     int32_t mStart = -1;
     74     int32_t mStop = -1;
     75 };
     76 
     77 }  // namespace net
     78 
     79 }  // namespace android
     80 
     81 #endif  // NETD_SERVER_ANDROID_NET_UID_RANGE_H
     82