Home | History | Annotate | Download | only in utils
      1 /*
      2  * Copyright (C) 2010 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 ANDROID_UTILS_FLATTENABLE_H
     18 #define ANDROID_UTILS_FLATTENABLE_H
     19 
     20 
     21 #include <stdint.h>
     22 #include <sys/types.h>
     23 #include <utils/Errors.h>
     24 
     25 namespace android {
     26 
     27 class Flattenable
     28 {
     29 public:
     30     // size in bytes of the flattened object
     31     virtual size_t getFlattenedSize() const = 0;
     32 
     33     // number of file descriptors to flatten
     34     virtual size_t getFdCount() const = 0;
     35 
     36     // flattens the object into buffer.
     37     // size should be at least of getFlattenedSize()
     38     // file descriptors are written in the fds[] array but ownership is
     39     // not transfered (ie: they must be dupped by the caller of
     40     // flatten() if needed).
     41     virtual status_t flatten(void* buffer, size_t size,
     42             int fds[], size_t count) const = 0;
     43 
     44     // unflattens the object from buffer.
     45     // size should be equal to the value of getFlattenedSize() when the
     46     // object was flattened.
     47     // unflattened file descriptors are found in the fds[] array and
     48     // don't need to be dupped(). ie: the caller of unflatten doesn't
     49     // keep ownership. If a fd is not retained by unflatten() it must be
     50     // explicitly closed.
     51     virtual status_t unflatten(void const* buffer, size_t size,
     52             int fds[], size_t count) = 0;
     53 
     54 protected:
     55     virtual ~Flattenable() = 0;
     56 
     57 };
     58 
     59 }; // namespace android
     60 
     61 
     62 #endif /* ANDROID_UTILS_FLATTENABLE_H */
     63