sensord: resize message size
[platform/core/system/sensord.git] / src / shared / message.h
1 /*
2  * sensord
3  *
4  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifndef __MESSAGE_H__
21 #define __MESSAGE_H__
22
23 #include <stdlib.h> /* size_t */
24 #include <atomic>
25
26 #define MAX_MSG_CAPACITY 10240
27 #define MAX_HEADER_RESERVED 3
28
29 namespace ipc {
30
31 typedef struct message_header {
32         uint64_t id;
33         uint32_t type;
34         size_t length;
35         int32_t err;
36         void *ancillary[MAX_HEADER_RESERVED];
37 } message_header;
38
39 class message {
40 public:
41         message(size_t capacity = MAX_MSG_CAPACITY);
42         message(const void *msg, size_t size);
43         message(const message &msg);
44         message(int err);
45         ~message();
46
47         void enclose(const void *msg, const size_t size);
48         void enclose(int error);
49         void disclose(void *msg);
50
51         uint32_t type(void);
52         void set_type(uint32_t type);
53
54         size_t size(void);
55
56         void ref(void);
57         void unref(void);
58         int  ref_count(void);
59
60         message_header *header(void);
61         char *body(void);
62
63 private:
64         message_header m_header;
65         size_t m_size;
66         size_t m_capacity;
67
68         char *m_msg;
69         std::atomic<int> ref_cnt;
70 };
71
72 }
73
74 #endif /* __MESSAGE_H__ */