1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/*
* libsf-common
*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: JuHyun Kim <jh8212.kim@samsung.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#if !defined(_CSOCK_CLASS_H_)
#define _CSOCK_CLASS_H_
#include <cipc_worker.h>
class csock : public cmutex
{
public:
enum sock_type_t {
SOCK_IPC = 0x01,
SOCK_NET = 0x02,
SOCK_TCP = 0x04,
SOCK_UDP = 0x08,
SOCK_WORKER = 0x10,
};
struct thread_arg_t {
csock *sock;
int client_handle;
cipc_worker *worker;
void *client_ctx;
};
csock(int handle, int mode = 0x15);
csock(char *name, int mode, int port, int server = 0);
virtual ~csock(void);
bool connect_to_server(void);
bool wait_for_client(void);
bool is_connected(void);
void set_on_close(bool on_close = true);
void set_worker(void *(*start)(void *data), void *(*running)(void *data), void *(*stop)(void *data));
void set_client_ctx(void *client_ctx);
void *client_ctx();
bool recv(void *buffer, int len);
bool send(void *buffer, int len);
int handle(void);
int mode(void);
bool disconnect(void);
static void *thread_tcp_main(void *arg);
static void *worker_terminate(void *data);
private:
int m_handle;
char *m_name;
sockaddr_un m_addr;
sockaddr_in m_net_addr;
void *(*m_start)(void *data);
void *(*m_running)(void *data);
void *(*m_stop)(void *data);
void *m_client_ctx;
pthread_t m_thid;
bool m_on_close;
int m_mode;
};
#endif
//! End of a file
|