summaryrefslogtreecommitdiff
path: root/xc/workInProgress/MTXserver/include/cit.h
blob: d977363569a901c8a9bd4451ace432a84104864f (plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

/************************************************************************
 *
 * cit.h --
 *
 *
 * Copyright 1992, 1993 Data General Corporation;
 * Copyright 1992, 1993 OMRON Corporation  
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation, and
 * that neither the name OMRON or DATA GENERAL be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission of the party whose name is to be used.  Neither 
 * OMRON or DATA GENERAL make any representation about the suitability of this
 * software for any purpose.  It is provided "as is" without express or 
 * implied warranty.  
 *
 * OMRON AND DATA GENERAL EACH DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
 * IN NO EVENT SHALL OMRON OR DATA GENERAL BE LIABLE FOR ANY SPECIAL, INDIRECT
 * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
 * OF THIS SOFTWARE.
 *
 ************************************************************************/

/* $XConsortium: cit.h,v 1.2 94/01/11 20:54:43 rob Exp $ */

#ifndef CIT_H
#define CIT_H

#include "misc.h"


/***********************************************************************/

#define RECALCULATE_NEXT_FREE_CLIENT(cid)				\
{									\
    if ((cid) < nextFreeClientID)					\
    {									\
        nextFreeClientID = (cid);					\
    }									\
    clients[(cid)] = NullClient;					\
									\
    while (!clients[currentMaxClients-1])				\
    {									\
	currentMaxClients--;						\
    }									\
}

/***********************************************************************/

#define get_req_len(req,cli) ((cli)->swapped ? 				\
                              lswaps((req)->length) : (req)->length)

#define get_big_req_len(req,cli) ((cli)->swapped ? 			\
                                  lswapl(((xBigReq *)(req))->length) : 	\
                                  ((xBigReq *)(req))->length)
typedef struct {
        CARD8 reqType;
        CARD8 data;
        CARD16 zero B16;
        CARD32 length B32;
} xBigReq;

/***********************************************************************/

#define GET_BYTES_NEEDED(client, gotnow, needed, move_header)		\
{									\
    if (gotnow < sizeof(xReq))                                          \
    {									\
        needed = sizeof(xReq);						\
    }									\
    else								\
    {									\
        needed = get_req_len((xReq *)oci->bufptr, client);		\
        if (!needed && client->big_requests)				\
        {								\
            move_header = TRUE;						\
            if (gotnow < sizeof(xBigReq))				\
            {								\
                needed = sizeof(xBigReq) >> 2;				\
            }								\
            else							\
            {								\
                needed = get_big_req_len((xReq *)oci->bufptr, client);	\
            }								\
        }								\
	client->req_len = needed;					\
	if (needed)							\
	{								\
	    needed <<= 2;						\
	}								\
	else								\
	{								\
	    needed = (client->big_requests) ? sizeof(xBigReq): sizeof(xReq);\
	}								\
    }									\
}

/***********************************************************************/

#define READ_REQUEST_FROM_CLIENT(gotnow, client)			\
{									\
    register Bool move_header = FALSE;					\
    register int needed;						\
    register ConnectionInputPtr oci;					\
									\
    oci = ((OsCommPtr) client->osPrivate)->input;			\
									\
    oci->bufptr += oci->lenLastReq;					\
    gotnow = oci->bufcnt + oci->buffer - oci->bufptr;			\
									\
    GET_BYTES_NEEDED(client, gotnow, needed, move_header);		\
									\
    while (gotnow < needed)						\
    {									\
        gotnow = ReadRequestFromClient(client, gotnow, needed);		\
        if (gotnow <= 0)						\
        {								\
            goto close_down;						\
        }								\
        GET_BYTES_NEEDED(client, gotnow, needed, move_header);		\
    }									\
    oci->lenLastReq = needed;						\
    if (move_header)							\
    {									\
        register xReq *request;						\
									\
        request = (xReq *)oci->bufptr;					\
        oci->bufptr += (sizeof(xBigReq) - sizeof(xReq));		\
        *(xReq *)oci->bufptr = *request;				\
        oci->lenLastReq -= (sizeof(xBigReq) - sizeof(xReq));		\
        client->req_len -= (sizeof(xBigReq) - sizeof(xReq)) >> 2;	\
    }									\
    client->requestBuffer = (pointer)oci->bufptr;			\
}

/***********************************************************************/

/* exported functions */

extern Bool            CreateClientInputThread();
extern void	       CloseDownClient();
extern void	       KillAllClients();
extern void	       CloseDownRetainedResources();
extern void	       InitClientGlobals();
extern void	       InitClient();
extern unsigned long   GetNextSerialNumber();
extern void	       MarkClientException();

#endif /* CIT_H */