tizen 2.3 release
[apps/livebox/data-provider-master.git] / include / service_common.h
1 /*
2  * Copyright 2013  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 enum tcb_type {
17         TCB_CLIENT_TYPE_APP     = 0x00,
18         TCB_CLIENT_TYPE_SERVICE = 0x01,
19         TCB_CLIENT_TYPE_UNKNOWN = 0xff
20 };
21
22 enum tcb_event_type {
23         TCB_EVENT_CREATE = 0x01,
24         TCB_EVENT_DESTROY = 0x02
25 };
26
27 struct tcb;
28 struct service_context;
29 struct service_event_item;
30
31 extern int tcb_fd(struct tcb *tcb);
32
33 /*!
34  * \remarks This function will return valid pid only after it gets the packet from a client.
35  *          or it will returns -1.
36  * \param[in] Thread Control Block
37  * \return pid Process Id
38  * \retval -1 TCB is not valid or the client is remote host. so we cannot get the PID of it.
39  * \retval >0 Process Id (PID)
40  */
41 extern int tcb_pid(struct tcb *tcb);
42
43 extern struct service_context *tcb_svc_ctx(struct tcb *tcb);
44 extern int tcb_client_type(struct tcb *tcb);
45 extern int tcb_client_type_set(struct tcb *tcb, enum tcb_type type);
46 extern int tcb_is_valid(struct service_context *svc_ctx, struct tcb *tcb);
47
48 extern struct service_context *service_common_create(const char *addr, int (*service_thread_main)(struct tcb *tcb, struct packet *packet, void *data), void *data);
49 extern int service_common_destroy(struct service_context *svc_ctx);
50
51 extern int service_common_multicast_packet(struct tcb *tcb, struct packet *packet, int type);
52 extern int service_common_unicast_packet(struct tcb *tcb, struct packet *packet);
53
54 extern struct service_event_item *service_common_add_timer(struct service_context *svc_ctx, double timer, int (*timer_cb)(struct service_context *svc_cx, void *data), void *data);
55 extern int service_common_update_timer(struct service_event_item *item, double timer);
56 extern int service_common_del_timer(struct service_context *svc_ctx, struct service_event_item *item);
57
58 extern int service_common_fd(struct service_context *ctx);
59
60 extern int service_register_tcb_callback(struct service_context *svc_ctx, struct tcb *tcb, enum tcb_event_type event, void (*cb)(struct service_context *svc_ctx, struct tcb *tcb, void *data), void *data);
61 extern int service_unregister_tcb_callback(struct service_context *svc_ctx, struct tcb *tcb, enum tcb_event_type event, void (*cb)(struct service_context *svc_ctx, struct tcb *tcb, void *data), void *data);
62
63 /* End of a file */