~ubuntu-branches/ubuntu/gutsy/virtualbox-ose/gutsy

« back to all changes in this revision

Viewing changes to src/libs/xpcom18a4/ipc/ipcd/daemon/src/ipcClient.h

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-09-08 16:44:58 UTC
  • Revision ID: james.westby@ubuntu.com-20070908164458-wao29470vqtr8ksy
Tags: upstream-1.5.0-dfsg2
ImportĀ upstreamĀ versionĀ 1.5.0-dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
3
 *
 
4
 * The contents of this file are subject to the Mozilla Public License Version
 
5
 * 1.1 (the "License"); you may not use this file except in compliance with
 
6
 * the License. You may obtain a copy of the License at
 
7
 * http://www.mozilla.org/MPL/
 
8
 *
 
9
 * Software distributed under the License is distributed on an "AS IS" basis,
 
10
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
11
 * for the specific language governing rights and limitations under the
 
12
 * License.
 
13
 *
 
14
 * The Original Code is Mozilla IPC.
 
15
 *
 
16
 * The Initial Developer of the Original Code is
 
17
 * Netscape Communications Corporation.
 
18
 * Portions created by the Initial Developer are Copyright (C) 2002
 
19
 * the Initial Developer. All Rights Reserved.
 
20
 *
 
21
 * Contributor(s):
 
22
 *   Darin Fisher <darin@netscape.com>
 
23
 *
 
24
 * Alternatively, the contents of this file may be used under the terms of
 
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
28
 * of those above. If you wish to allow use of your version of this file only
 
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
30
 * use your version of this file under the terms of the MPL, indicate your
 
31
 * decision by deleting the provisions above and replace them with the notice
 
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
33
 * the provisions above, a recipient may use your version of this file under
 
34
 * the terms of any one of the MPL, the GPL or the LGPL.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
#ifndef ipcClientUnix_h__
 
39
#define ipcClientUnix_h__
 
40
 
 
41
#include "prio.h"
 
42
#include "ipcMessageQ.h"
 
43
#include "ipcStringList.h"
 
44
#include "ipcIDList.h"
 
45
 
 
46
#ifdef XP_WIN
 
47
#include <windows.h>
 
48
#endif
 
49
 
 
50
//-----------------------------------------------------------------------------
 
51
// ipcClient
 
52
//
 
53
// NOTE: this class is an implementation detail of the IPC daemon. IPC daemon
 
54
// modules (other than the built-in IPCM module) must not access methods on
 
55
// this class directly. use the API provided via ipcd.h instead.
 
56
//-----------------------------------------------------------------------------
 
57
 
 
58
class ipcClient
 
59
{
 
60
public:
 
61
    void Init();
 
62
    void Finalize();
 
63
 
 
64
    PRUint32 ID() const { return mID; }
 
65
 
 
66
    void   AddName(const char *name);
 
67
    void   DelName(const char *name);
 
68
    PRBool HasName(const char *name) const { return mNames.Find(name) != NULL; }
 
69
 
 
70
    void   AddTarget(const nsID &target);
 
71
    void   DelTarget(const nsID &target);
 
72
    PRBool HasTarget(const nsID &target) const { return mTargets.Find(target) != NULL; }
 
73
 
 
74
    // list iterators
 
75
    const ipcStringNode *Names()   const { return mNames.First(); }
 
76
    const ipcIDNode     *Targets() const { return mTargets.First(); }
 
77
 
 
78
    // returns primary client name (the one specified in the "client hello" message)
 
79
    const char *PrimaryName() const { return mNames.First() ? mNames.First()->Value() : NULL; }
 
80
 
 
81
    void   SetExpectsSyncReply(PRBool val) { mExpectsSyncReply = val; }
 
82
    PRBool GetExpectsSyncReply() const     { return mExpectsSyncReply; }
 
83
 
 
84
#ifdef XP_WIN
 
85
    PRUint32 PID() const { return mPID; }
 
86
    void SetPID(PRUint32 pid) { mPID = pid; }
 
87
 
 
88
    HWND Hwnd() const { return mHwnd; }
 
89
    void SetHwnd(HWND hwnd) { mHwnd = hwnd; }
 
90
#endif
 
91
 
 
92
#if defined(XP_UNIX) || defined(XP_OS2)
 
93
    //
 
94
    // called to process a client file descriptor.  the value of pollFlags
 
95
    // indicates the state of the socket.
 
96
    //
 
97
    // returns:
 
98
    //   0             - to cancel client connection  
 
99
    //   PR_POLL_READ  - to poll for a readable socket
 
100
    //   PR_POLL_WRITE - to poll for a writable socket
 
101
    //   (both flags)  - to poll for either a readable or writable socket
 
102
    //
 
103
    // the socket is non-blocking.
 
104
    // 
 
105
    int Process(PRFileDesc *sockFD, int pollFlags);
 
106
 
 
107
    //
 
108
    // on success or failure, this function takes ownership of |msg| and will
 
109
    // delete it when appropriate.
 
110
    //
 
111
    void EnqueueOutboundMsg(ipcMessage *msg) { mOutMsgQ.Append(msg); }
 
112
#endif
 
113
 
 
114
private:
 
115
    static PRUint32 gLastID;
 
116
 
 
117
    PRUint32      mID;
 
118
    ipcStringList mNames;
 
119
    ipcIDList     mTargets;
 
120
    PRBool        mExpectsSyncReply;
 
121
 
 
122
#ifdef XP_WIN
 
123
    // on windows, we store the PID of the client process to help us determine
 
124
    // the client from which a message originated.  each message has the PID
 
125
    // encoded in it.
 
126
    PRUint32      mPID;
 
127
    
 
128
    // the hwnd of the client's message window.
 
129
    HWND          mHwnd;
 
130
#endif
 
131
 
 
132
#if defined(XP_UNIX) || defined(XP_OS2)
 
133
    ipcMessage    mInMsg;    // buffer for incoming message
 
134
    ipcMessageQ   mOutMsgQ;  // outgoing message queue
 
135
 
 
136
    // keep track of the amount of the first message sent
 
137
    PRUint32      mSendOffset;
 
138
 
 
139
    // utility function for writing out messages.
 
140
    int WriteMsgs(PRFileDesc *fd);
 
141
#endif
 
142
};
 
143
 
 
144
#endif // !ipcClientUnix_h__