[REFACTOR] encapsulate target struct (part 1)
[platform/core/system/swap-manager.git] / daemon / target.h
1 /*
2  *  DA manager
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Vyacheslav Cherkashin <v.cherkashin@samsung.com>
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  * Contributors:
23  * - Samsung RnD Institute Russia
24  *
25  */
26
27
28 #ifndef _TARGER_H_
29 #define _TARGER_H_
30
31
32 #include <inttypes.h>
33 #include <pthread.h>
34
35 #include <Ecore.h>
36
37 #include "da_protocol.h"
38
39
40 #define UNKNOWN_PID             ((pid_t)(-1))
41 #define UNKNOWN_FD              (-1)
42
43
44 struct target {
45         enum app_type_t app_type;       /* calculated when connecting */
46         int64_t allocmem;               /* written only by recv thread */
47         pid_t pid;                      /* written only by recv thread */
48         pid_t ppid;                     /* written only by recv thread */
49         int socket;                     /* written only by main thread */
50         pthread_t recv_thread;          /* written only by main thread */
51         int event_fd;                   /* for thread communication
52                                          * (from recv thread to main thread) */
53         int initial_log;                /* written only by main thread */
54         Ecore_Fd_Handler *handler;      /* calculated when connecting */
55 };
56
57
58 struct target *target_ctor(void);
59 void target_dtor(struct target *t);
60
61 int target_accept(struct target *t, int sockfd);
62
63 int target_send_msg(struct target *t, struct msg_target_t *msg);
64 int target_recv_msg(struct target *t, struct msg_target_t *msg);
65
66
67 int target_start(struct target *t, void *(*start_routine) (void *));
68 int target_wait(struct target *t);
69
70
71 pid_t target_get_pid(struct target *t);
72 void target_set_pid(struct target *t, pid_t pid);
73
74 pid_t target_get_ppid(struct target *t);
75 void target_set_ppid(struct target *t, pid_t ppid);
76
77
78 void target_cnt_set(int cnt);
79 int target_cnt_get(void);
80 int target_cnt_sub_and_fetch(void);
81
82 struct target *target_get(int i);
83
84 /* for all targets */
85 int target_send_msg_to_all(struct msg_target_t *msg);
86 void target_wait_all(void);
87 uint64_t target_get_total_alloc(pid_t pid);
88
89
90 #endif /* _TARGER_H_ */