michael@0: /* michael@0: * Copyright (C) 2010 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef ANDROID_UTILS_FLATTENABLE_H michael@0: #define ANDROID_UTILS_FLATTENABLE_H michael@0: michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: namespace android { michael@0: michael@0: class Flattenable michael@0: { michael@0: public: michael@0: // size in bytes of the flattened object michael@0: virtual size_t getFlattenedSize() const = 0; michael@0: michael@0: // number of file descriptors to flatten michael@0: virtual size_t getFdCount() const = 0; michael@0: michael@0: // flattens the object into buffer. michael@0: // size should be at least of getFlattenedSize() michael@0: // file descriptors are written in the fds[] array but ownership is michael@0: // not transfered (ie: they must be dupped by the caller of michael@0: // flatten() if needed). michael@0: virtual status_t flatten(void* buffer, size_t size, michael@0: int fds[], size_t count) const = 0; michael@0: michael@0: // unflattens the object from buffer. michael@0: // size should be equal to the value of getFlattenedSize() when the michael@0: // object was flattened. michael@0: // unflattened file descriptors are found in the fds[] array and michael@0: // don't need to be dupped(). ie: the caller of unflatten doesn't michael@0: // keep ownership. If a fd is not retained by unflatten() it must be michael@0: // explicitly closed. michael@0: virtual status_t unflatten(void const* buffer, size_t size, michael@0: int fds[], size_t count) = 0; michael@0: michael@0: protected: michael@0: virtual ~Flattenable() = 0; michael@0: michael@0: }; michael@0: michael@0: }; // namespace android michael@0: michael@0: michael@0: #endif /* ANDROID_UTILS_FLATTENABLE_H */