105b261ecSmrg/***********************************************************
205b261ecSmrgCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
305b261ecSmrg
405b261ecSmrg                        All Rights Reserved
505b261ecSmrg
605b261ecSmrgPermission to use, copy, modify, and distribute this software and its
705b261ecSmrgdocumentation for any purpose and without fee is hereby granted,
805b261ecSmrgprovided that the above copyright notice appear in all copies and that
905b261ecSmrgboth that copyright notice and this permission notice appear in
1005b261ecSmrgsupporting documentation, and that the name of Digital not be
1105b261ecSmrgused in advertising or publicity pertaining to distribution of the
1205b261ecSmrgsoftware without specific, written prior permission.
1305b261ecSmrg
1405b261ecSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
1505b261ecSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
1605b261ecSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
1705b261ecSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
1805b261ecSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
1905b261ecSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
2005b261ecSmrgSOFTWARE.
2105b261ecSmrg
2205b261ecSmrg******************************************************************/
2305b261ecSmrg
2405b261ecSmrg#ifndef DIXSTRUCT_H
2505b261ecSmrg#define DIXSTRUCT_H
2605b261ecSmrg
2735c4bbdfSmrg#include "client.h"
2805b261ecSmrg#include "dix.h"
2905b261ecSmrg#include "resource.h"
3005b261ecSmrg#include "cursor.h"
3105b261ecSmrg#include "gc.h"
3205b261ecSmrg#include "pixmap.h"
334642e01fSmrg#include "privates.h"
3405b261ecSmrg#include <X11/Xmd.h>
3505b261ecSmrg
3605b261ecSmrg/*
3705b261ecSmrg * 	direct-mapped hash table, used by resource manager to store
3805b261ecSmrg *      translation from client ids to server addresses.
3905b261ecSmrg */
4005b261ecSmrg
416747b715Smrgextern _X_EXPORT CallbackListPtr ClientStateCallback;
4205b261ecSmrg
4305b261ecSmrgtypedef struct {
4435c4bbdfSmrg    ClientPtr client;
4535c4bbdfSmrg    xConnSetupPrefix *prefix;
4635c4bbdfSmrg    xConnSetup *setup;
4705b261ecSmrg} NewClientInfoRec;
4805b261ecSmrg
4935c4bbdfSmrgtypedef void (*ReplySwapPtr) (ClientPtr /* pClient */ ,
5035c4bbdfSmrg                              int /* size */ ,
5135c4bbdfSmrg                              void * /* pbuf */ );
5235c4bbdfSmrg
5335c4bbdfSmrgextern _X_EXPORT void
5435c4bbdfSmrgReplyNotSwappd(ClientPtr /* pClient */ ,
5535c4bbdfSmrg               int /* size */ ,
5635c4bbdfSmrg               void * /* pbuf */ ) _X_NORETURN;
5735c4bbdfSmrg
5835c4bbdfSmrgtypedef enum { ClientStateInitial,
5935c4bbdfSmrg    ClientStateRunning,
6035c4bbdfSmrg    ClientStateRetained,
6135c4bbdfSmrg    ClientStateGone
6235c4bbdfSmrg} ClientState;
6335c4bbdfSmrg
6405b261ecSmrgtypedef struct _saveSet {
6535c4bbdfSmrg    struct _Window *windowPtr;
6635c4bbdfSmrg    Bool toRoot;
6735c4bbdfSmrg    Bool map;
6805b261ecSmrg} SaveSetElt;
6905b261ecSmrg#define SaveSetWindow(ss)   ((ss).windowPtr)
7005b261ecSmrg#define SaveSetToRoot(ss)   ((ss).toRoot)
714642e01fSmrg#define SaveSetShouldMap(ss)	    ((ss).map)
7205b261ecSmrg#define SaveSetAssignWindow(ss,w)   ((ss).windowPtr = (w))
7305b261ecSmrg#define SaveSetAssignToRoot(ss,tr)  ((ss).toRoot = (tr))
744642e01fSmrg#define SaveSetAssignMap(ss,m)      ((ss).map = (m))
7505b261ecSmrg
7605b261ecSmrgtypedef struct _Client {
7735c4bbdfSmrg    void *requestBuffer;
7835c4bbdfSmrg    void *osPrivate;             /* for OS layer, including scheduler */
791b5d61b8Smrg    struct xorg_list ready;      /* List of clients ready to run */
801b5d61b8Smrg    struct xorg_list output_pending; /* List of clients with output queued */
8135c4bbdfSmrg    Mask clientAsMask;
8235c4bbdfSmrg    short index;
8335c4bbdfSmrg    unsigned char majorOp, minorOp;
8435c4bbdfSmrg    unsigned int swapped:1;
8535c4bbdfSmrg    unsigned int local:1;
8635c4bbdfSmrg    unsigned int big_requests:1; /* supports large requests */
8735c4bbdfSmrg    unsigned int clientGone:1;
8835c4bbdfSmrg    unsigned int closeDownMode:2;
8935c4bbdfSmrg    unsigned int clientState:2;
9035c4bbdfSmrg    signed char smart_priority;
9135c4bbdfSmrg    short noClientException;      /* this client died or needs to be killed */
9235c4bbdfSmrg    int priority;
9305b261ecSmrg    ReplySwapPtr pSwapReplyFunc;
9435c4bbdfSmrg    XID errorValue;
9535c4bbdfSmrg    int sequence;
9635c4bbdfSmrg    int ignoreCount;            /* count for Attend/IgnoreClient */
9735c4bbdfSmrg    int numSaved;
9835c4bbdfSmrg    SaveSetElt *saveSet;
9935c4bbdfSmrg    int (**requestVector) (ClientPtr /* pClient */ );
10035c4bbdfSmrg    CARD32 req_len;             /* length of current request */
10135c4bbdfSmrg    unsigned int replyBytesRemaining;
10235c4bbdfSmrg    PrivateRec *devPrivates;
10335c4bbdfSmrg    unsigned short mapNotifyMask;
10435c4bbdfSmrg    unsigned short newKeyboardNotifyMask;
1051b5d61b8Smrg    unsigned char xkbClientFlags;
10635c4bbdfSmrg    KeyCode minKC, maxKC;
10735c4bbdfSmrg
10835c4bbdfSmrg    int smart_start_tick;
10935c4bbdfSmrg    int smart_stop_tick;
11035c4bbdfSmrg
1114642e01fSmrg    DeviceIntPtr clientPtr;
11235c4bbdfSmrg    ClientIdPtr clientIds;
11335c4bbdfSmrg    int req_fds;
11435c4bbdfSmrg} ClientRec;
11535c4bbdfSmrg
11635c4bbdfSmrgstatic inline void
11735c4bbdfSmrgSetReqFds(ClientPtr client, int req_fds) {
11835c4bbdfSmrg    if (client->req_fds != 0 && req_fds != client->req_fds)
11935c4bbdfSmrg        LogMessage(X_ERROR, "Mismatching number of request fds %d != %d\n", req_fds, client->req_fds);
12035c4bbdfSmrg    client->req_fds = req_fds;
12135c4bbdfSmrg}
12205b261ecSmrg
12305b261ecSmrg/*
12405b261ecSmrg * Scheduling interface
12505b261ecSmrg */
12635c4bbdfSmrgextern long SmartScheduleTime;
12735c4bbdfSmrgextern long SmartScheduleInterval;
12835c4bbdfSmrgextern long SmartScheduleSlice;
12935c4bbdfSmrgextern long SmartScheduleMaxSlice;
1301b5d61b8Smrg#ifdef HAVE_SETITIMER
1311b5d61b8Smrgextern Bool SmartScheduleSignalEnable;
1321b5d61b8Smrg#else
1331b5d61b8Smrg#define SmartScheduleSignalEnable FALSE
1341b5d61b8Smrg#endif
13535c4bbdfSmrgextern void SmartScheduleStartTimer(void);
13635c4bbdfSmrgextern void SmartScheduleStopTimer(void);
13735c4bbdfSmrg
1381b5d61b8Smrg/* Client has requests queued or data on the network */
1391b5d61b8Smrgvoid mark_client_ready(ClientPtr client);
1401b5d61b8Smrg
1411b5d61b8Smrg/*
1421b5d61b8Smrg * Client has requests queued or data on the network, but awaits a
1431b5d61b8Smrg * server grab release
1441b5d61b8Smrg */
1451b5d61b8Smrgvoid mark_client_saved_ready(ClientPtr client);
1461b5d61b8Smrg
1471b5d61b8Smrg/* Client has no requests queued and no data on network */
1481b5d61b8Smrgvoid mark_client_not_ready(ClientPtr client);
1491b5d61b8Smrg
1501b5d61b8Smrgstatic inline Bool client_is_ready(ClientPtr client)
1511b5d61b8Smrg{
1521b5d61b8Smrg    return !xorg_list_is_empty(&client->ready);
1531b5d61b8Smrg}
1541b5d61b8Smrg
1551b5d61b8SmrgBool
1561b5d61b8Smrgclients_are_ready(void);
1571b5d61b8Smrg
1581b5d61b8Smrgextern struct xorg_list output_pending_clients;
1591b5d61b8Smrg
1601b5d61b8Smrgstatic inline void
1611b5d61b8Smrgoutput_pending_mark(ClientPtr client)
1621b5d61b8Smrg{
1631b5d61b8Smrg    if (!client->clientGone && xorg_list_is_empty(&client->output_pending))
1641b5d61b8Smrg        xorg_list_append(&client->output_pending, &output_pending_clients);
1651b5d61b8Smrg}
1661b5d61b8Smrg
1671b5d61b8Smrgstatic inline void
1681b5d61b8Smrgoutput_pending_clear(ClientPtr client)
1691b5d61b8Smrg{
1701b5d61b8Smrg    xorg_list_del(&client->output_pending);
1711b5d61b8Smrg}
1721b5d61b8Smrg
1731b5d61b8Smrgstatic inline Bool any_output_pending(void) {
1741b5d61b8Smrg    return !xorg_list_is_empty(&output_pending_clients);
1751b5d61b8Smrg}
1761b5d61b8Smrg
17705b261ecSmrg#define SMART_MAX_PRIORITY  (20)
17805b261ecSmrg#define SMART_MIN_PRIORITY  (-20)
17905b261ecSmrg
18035c4bbdfSmrgextern void SmartScheduleInit(void);
18105b261ecSmrg
18205b261ecSmrg/* This prototype is used pervasively in Xext, dix */
18305b261ecSmrg#define DISPATCH_PROC(func) int func(ClientPtr /* client */)
18405b261ecSmrg
18505b261ecSmrgtypedef struct _WorkQueue {
18605b261ecSmrg    struct _WorkQueue *next;
18735c4bbdfSmrg    Bool (*function) (ClientPtr /* pClient */ ,
18835c4bbdfSmrg                      void *    /* closure */
18935c4bbdfSmrg        );
19035c4bbdfSmrg    ClientPtr client;
19135c4bbdfSmrg    void *closure;
19235c4bbdfSmrg} WorkQueueRec;
19305b261ecSmrg
1946747b715Smrgextern _X_EXPORT TimeStamp currentTime;
19505b261ecSmrg
19635c4bbdfSmrgextern _X_EXPORT int
19735c4bbdfSmrgCompareTimeStamps(TimeStamp /*a */ ,
19835c4bbdfSmrg                  TimeStamp /*b */ );
19905b261ecSmrg
20035c4bbdfSmrgextern _X_EXPORT TimeStamp
20135c4bbdfSmrgClientTimeToServerTime(CARD32 /*c */ );
20205b261ecSmrg
20305b261ecSmrgtypedef struct _CallbackRec {
20435c4bbdfSmrg    CallbackProcPtr proc;
20535c4bbdfSmrg    void *data;
20635c4bbdfSmrg    Bool deleted;
20735c4bbdfSmrg    struct _CallbackRec *next;
20805b261ecSmrg} CallbackRec, *CallbackPtr;
20905b261ecSmrg
21005b261ecSmrgtypedef struct _CallbackList {
21135c4bbdfSmrg    int inCallback;
21235c4bbdfSmrg    Bool deleted;
21335c4bbdfSmrg    int numDeleted;
21435c4bbdfSmrg    CallbackPtr list;
21505b261ecSmrg} CallbackListRec;
21605b261ecSmrg
21705b261ecSmrg/* proc vectors */
21805b261ecSmrg
21935c4bbdfSmrgextern int (*InitialVector[3]) (ClientPtr /*client */ );
22005b261ecSmrg
22135c4bbdfSmrgextern _X_EXPORT int (*ProcVector[256]) (ClientPtr /*client */ );
22205b261ecSmrg
22335c4bbdfSmrgextern _X_EXPORT int (*SwappedProcVector[256]) (ClientPtr /*client */ );
22405b261ecSmrg
22535c4bbdfSmrgextern ReplySwapPtr ReplySwapVector[256];
22605b261ecSmrg
22735c4bbdfSmrgextern _X_EXPORT int
22835c4bbdfSmrgProcBadRequest(ClientPtr /*client */ );
22905b261ecSmrg
23035c4bbdfSmrg#endif                          /* DIXSTRUCT_H */
231