isns_task.h revision 1.1 1 /* $NetBSD: isns_task.h,v 1.1 2011/01/16 01:22:50 agc Exp $ */
2
3 /*-
4 * Copyright (c) 2004,2009 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Wasabi Systems, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31 /*
32 * isns_task.h
33 */
34
35 #ifndef _ISNS_TASK_H_
36 #define _ISNS_TASK_H_
37
38 #include <sys/event.h>
39
40 #define ISNS_TASK_DISCOVER_SERVER 0
41 #define ISNS_TASK_RECONNECT_SERVER 1
42 #define ISNS_TASK_SEND_PDU 2
43 #define ISNS_TASK_INIT_SOCKET_IO 3
44 #define ISNS_TASK_INIT_REFRESH 4
45 #define ISNS_NUM_TASKS 5
46
47
48 union isns_task_var_u {
49 struct {
50 struct isns_trans_s *trans_p;
51 struct isns_pdu_s *pdu_p;
52 } send_pdu;
53
54 struct {
55 struct addrinfo *ai_p;
56 } reconnect_server;
57
58 struct {
59 isns_socket_t sd;
60 struct addrinfo *ai_p;
61 } init_socket_io;
62
63 struct {
64 struct isns_refresh_s *ref_p;
65 } init_refresh;
66
67 void *data_p;
68 };
69
70 struct isns_task_s {
71 uint8_t task_type;
72 struct isns_config_s *cfg_p;
73 union isns_task_var_u var;
74
75 int waitable;
76 pthread_mutex_t wait_mutex;
77 pthread_cond_t wait_condvar;
78 int wait_ref_count;
79
80 SIMPLEQ_ENTRY(isns_task_s) taskq_entry;
81 };
82
83 typedef void (isns_task_handler)(struct isns_task_s *);
84
85 void isns_run_task(struct isns_task_s *);
86 void isns_end_task(struct isns_task_s *);
87 int isns_wait_task(struct isns_task_s *, const struct timespec *);
88
89 struct isns_task_s *isns_new_task(struct isns_config_s *, uint8_t, int);
90 void isns_free_task(struct isns_task_s *);
91 void isns_taskq_insert_tail(struct isns_config_s *, struct isns_task_s *);
92 void isns_taskq_insert_head(struct isns_config_s *, struct isns_task_s *);
93 struct isns_task_s *isns_taskq_remove(struct isns_config_s *);
94 struct isns_task_s *isns_taskq_remove_trans(struct isns_config_s *, uint16_t);
95
96
97 #endif /* !_ISNS_TASK_H_ */
98