2 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
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.
18 TCB_CLIENT_TYPE_APP = 0x00,
19 TCB_CLIENT_TYPE_SERVICE = 0x01,
20 TCB_CLIENT_TYPE_UNKNOWN = 0xff,
24 struct service_context;
25 struct service_event_item;
27 extern int tcb_fd(struct tcb *tcb);
28 extern struct service_context *tcb_svc_ctx(struct tcb *tcb);
29 extern int tcb_client_type(struct tcb *tcb);
30 extern int tcb_client_type_set(struct tcb *tcb, enum tcb_type type);
32 extern struct service_context *service_common_create(const char *addr, int (*service_thread_main)(struct tcb *tcb, struct packet *packet, void *data), void *data);
33 extern int service_common_destroy(struct service_context *svc_ctx);
35 extern int service_common_multicast_packet(struct tcb *tcb, struct packet *packet, int type);
36 extern int service_common_unicast_packet(struct tcb *tcb, struct packet *packet);
38 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);
39 extern int service_common_del_timer(struct service_context *svc_ctx, struct service_event_item *item);
41 #define CRITICAL_SECTION_BEGIN(handle) \
44 ret = pthread_mutex_lock(handle); \
46 fprintf(stderr, "Failed to lock: %s\n", strerror(ret)); \
49 #define CRITICAL_SECTION_END(handle) \
52 ret = pthread_mutex_unlock(handle); \
54 fprintf(stderr, "Failed to unlock: %s\n", strerror(ret)); \
57 #define CANCEL_SECTION_BEGIN() do { \
59 ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); \
61 fprintf(stderr, "Unable to set cancelate state: %s\n", strerror(ret)); \
64 #define CANCEL_SECTION_END() do { \
66 ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); \
68 fprintf(stderr, "Unable to set cancelate state: %s\n", strerror(ret)); \
71 #define CLOSE_PIPE(p) do { \
73 status = close(p[PIPE_READ]); \
75 fprintf(stderr, "close: %s\n", strerror(errno)); \
76 status = close(p[PIPE_WRITE]); \
78 fprintf(stderr, "close: %s\n", strerror(errno)); \