2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_UTILS_FLATTENABLE_H
18 #define ANDROID_UTILS_FLATTENABLE_H
22 #include <sys/types.h>
23 #include <utils/Errors.h>
30 // size in bytes of the flattened object
31 virtual size_t getFlattenedSize() const = 0;
33 // number of file descriptors to flatten
34 virtual size_t getFdCount() const = 0;
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;
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
51 virtual status_t unflatten(void const* buffer, size_t size,
52 int fds[], size_t count) = 0;
55 virtual ~Flattenable() = 0;
59 }; // namespace android
62 #endif /* ANDROID_UTILS_FLATTENABLE_H */