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