2 * Copyright (c) 2000 - 2015 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 void print_cynara_error(int ret, char *msg);
42 int check_cynara(struct tcb *tcb);
44 #define CRITICAL_SECTION_BEGIN(handle) \
47 ret = pthread_mutex_lock(handle); \
49 fprintf(stderr, "Failed to lock: %s\n", strerror(ret)); \
52 #define CRITICAL_SECTION_END(handle) \
55 ret = pthread_mutex_unlock(handle); \
57 fprintf(stderr, "Failed to unlock: %s\n", strerror(ret)); \
60 #define CANCEL_SECTION_BEGIN() do { \
62 ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); \
64 fprintf(stderr, "Unable to set cancelate state: %s\n", strerror(ret)); \
67 #define CANCEL_SECTION_END() do { \
69 ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); \
71 fprintf(stderr, "Unable to set cancelate state: %s\n", strerror(ret)); \
74 #define CLOSE_PIPE(p) do { \
76 status = close(p[PIPE_READ]); \
78 fprintf(stderr, "close: %s\n", strerror(errno)); \
79 status = close(p[PIPE_WRITE]); \
81 fprintf(stderr, "close: %s\n", strerror(errno)); \