Timeout merge #3:
[opensync.git] / opensync / ipc / opensync_queue_private.h
blob13fd2d37de60bc43ed987836d5cd79a9b96cce94
1 /*
2 * libopensync - A synchronization framework
3 * Copyright (C) 2004-2005 Armin Bauer <armin.bauer@opensync.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef _OPENSYNC_QUEUE_PRIVATE_H
22 #define _OPENSYNC_QUEUE_PRIVATE_H
24 #include <fcntl.h>
25 #ifndef _WIN32
26 #include <sys/poll.h>
27 #include <sys/time.h>
28 #endif //_WIN32
30 #include <signal.h>
32 /**
33 * @defgroup OSyncQueuePrivateAPI OpenSync Queue Private
34 * @ingroup OSyncIPCPrivate
35 * @brief A Queue used for asynchronous communication between thread
38 /*@{*/
40 /*! @brief Represents a Queue which can be used to receive messages
42 struct OSyncQueue {
43 /** The queue type **/
44 OSyncQueueType type;
46 /** The real asynchronous queue from glib **/
47 int fd;
49 /** The path name of this queue **/
50 char *name;
52 /** The message handler for this queue **/
53 OSyncMessageHandler message_handler;
55 /** The user_data associated with this queue **/
56 gpointer user_data;
58 /** The source associated with this queue */
59 GSourceFuncs *incoming_functions;
60 GSource *incoming_source;
62 /** The context in which the IO of the queue is dispatched */
63 GMainContext *context;
64 GMainContext *incomingContext;
66 OSyncThread *thread;
68 GAsyncQueue *incoming;
69 GAsyncQueue *outgoing;
71 /** List of pending replies */
72 OSyncList *pendingReplies;
73 GMutex *pendingLock;
74 unsigned int pendingCount, pendingLimit;
76 GSourceFuncs *write_functions;
77 GSource *write_source;
79 GSourceFuncs *read_functions;
80 GSource *read_source;
82 /** Timeout Source **/
83 GSourceFuncs *timeout_functions;
84 GSource *timeout_source;
86 GMutex *disconnectLock;
88 /** Connection status **/
89 osync_bool connected;
91 /** Reference count **/
92 int ref_count;
94 /* Queue for replies to incoming messages */
95 OSyncQueue *reply_queue;
97 /* Queue for receiving commands we are replying to */
98 OSyncQueue *cmd_queue;
100 /* Disconnect in progress */
101 gboolean disc_in_progress;
103 /* Largest timeout value seen so far */
104 unsigned int max_timeout;
106 /* Expiration time of pending queue timeout */
107 GTimeVal pending_timeout;
110 /** @brief Pending queue timeout addition for ipc delay
112 #define OSYNC_QUEUE_PENDING_QUEUE_IPC_DELAY 1
114 /** @brief Pending queue minimum timeout
116 #define OSYNC_QUEUE_PENDING_QUEUE_MIN_TIMEOUT 20
118 /** @brief Timeout object
120 typedef struct OSyncTimeoutInfo {
121 /** Expiration date */
122 GTimeVal expiration;
123 } OSyncTimeoutInfo;
125 /** @brief Pending Message object
127 typedef struct OSyncPendingMessage {
128 /** ID of the expected Message */
129 long long int id;
130 /** Where should the reply be received? */
131 OSyncMessageHandler callback;
132 /** The user data */
133 gpointer user_data;
134 /** Message Timeout */
135 OSyncTimeoutInfo *timeout_info;
136 } OSyncPendingMessage;
139 * @brief Generate IDs
140 * Ids are generated as follows:
142 * the upper 6 bytes are the time in seconds and microseconds
143 * the lower 2 bytes are a random number
145 * */
146 static long long int opensync_queue_gen_id(const GTimeVal *tv);
148 /*@}*/
150 #endif /* _OPENSYNC_QUEUE_PRIVATE_H */