2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // manager - network protocol core manager class
25 #include <Security/ip++.h>
26 #include <Security/timeflow.h>
27 #include <Security/tqueue.h>
29 #include "connectionpool.h"
31 #include "parameters.h"
37 using namespace IPPlusPlus
;
50 // A Manager object represents the top-level operations controller.
51 // You would usually only have one per process, though you *can*
52 // have more than one - they would not interact at all, and each
53 // Protocol, Transfer, etc. object could only belong to one of them.
55 class Manager
: public ParameterPointer
{
61 void add(Transfer
*xfer
);
62 void remove(Transfer
*xfer
);
63 void start(Transfer
*xfer
);
64 void abort(Transfer
*xfer
);
66 Observer
*observer() const { return mObserver
; }
67 void observer(Observer
*ob
) { mObserver
= ob
; }
69 public: // meant for just Transfer and Connection
70 void done(Transfer
*xfer
);
72 void addIO(TransferEngine::Client
*client
);
73 void removeIO(TransferEngine::Client
*client
);
75 public: // meant just for Connection
76 template <class ProtoConnection
>
77 ProtoConnection
*findConnection(const HostTarget
&host
)
78 { return safe_cast
<ProtoConnection
*>(pickConnection(host
)); }
80 void retainConnection(Connection
*connection
);
81 void closeConnection(Connection
*connection
);
84 void step(); // one small step for URLkind...
85 void run(); // run until no more work
86 void run(Time::Absolute upTo
); // run until some future time
89 bool reuseConnections() const { return mRetainConnections
; }
90 void reuseConnections(bool retain
); // global connection reuse override
91 void flushConnections(); // clear connection cache (expensive)
94 class Timer
: private ScheduleQueue
<Time::Absolute
>::Event
{
99 Time::Absolute
when() const { return Event::when(); }
100 bool scheduled() const { return Event::scheduled(); }
103 virtual void action() = 0;
106 virtual void setTimer(Timer
*timer
, Time::Absolute when
);
107 void setTimer(Timer
*timer
, Time::Interval offset
)
108 { setTimer(timer
, Time::now() + offset
); }
110 virtual void clearTimer(Timer
*timer
);
113 virtual void runTimers(); // run ready timers
114 virtual void prepare(); // setup for engine
117 void doStep(); // internal operative step
118 Connection
*pickConnection(const HostTarget
&host
);
121 typedef map
<string
, Protocol
*> ProtoMap
;
122 ProtoMap mProtocols
; // map of registered protocols
125 typedef set
<Transfer
*> TransferSet
;
126 TransferSet mTransfers
; // set of active transfers (prelim)
127 uint32 mActiveTransfers
; // number of active transfers
130 TransferEngine mEngine
; // transfer core engine
131 ConnectionPool mConnections
; // pool of retained (live) Connections
132 set
<Connection
*> mMorgue
; // Connections we should destroy
133 bool mRetainConnections
; // global connection-reuse enable
134 Observer
*mObserver
; // default observer (NULL if none)
136 ScheduleQueue
<Time::Absolute
> mTimers
; // timer queue
140 } // end namespace Network
141 } // end namespace Security
144 #endif /* _H_NETMANAGER */