Committer:
donatien
Date:
Fri Aug 06 10:42:05 2010 +0000
Revision:
3:e02ec42cf9c8

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 3:e02ec42cf9c8 1
donatien 3:e02ec42cf9c8 2 /*
donatien 3:e02ec42cf9c8 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
donatien 3:e02ec42cf9c8 4
donatien 3:e02ec42cf9c8 5 Permission is hereby granted, free of charge, to any person obtaining a copy
donatien 3:e02ec42cf9c8 6 of this software and associated documentation files (the "Software"), to deal
donatien 3:e02ec42cf9c8 7 in the Software without restriction, including without limitation the rights
donatien 3:e02ec42cf9c8 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
donatien 3:e02ec42cf9c8 9 copies of the Software, and to permit persons to whom the Software is
donatien 3:e02ec42cf9c8 10 furnished to do so, subject to the following conditions:
donatien 3:e02ec42cf9c8 11
donatien 3:e02ec42cf9c8 12 The above copyright notice and this permission notice shall be included in
donatien 3:e02ec42cf9c8 13 all copies or substantial portions of the Software.
donatien 3:e02ec42cf9c8 14
donatien 3:e02ec42cf9c8 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
donatien 3:e02ec42cf9c8 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
donatien 3:e02ec42cf9c8 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
donatien 3:e02ec42cf9c8 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
donatien 3:e02ec42cf9c8 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 3:e02ec42cf9c8 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
donatien 3:e02ec42cf9c8 21 THE SOFTWARE.
donatien 3:e02ec42cf9c8 22 */
donatien 3:e02ec42cf9c8 23
donatien 3:e02ec42cf9c8 24 /**
donatien 3:e02ec42cf9c8 25 \file Net Service base class header file
donatien 3:e02ec42cf9c8 26 */
donatien 3:e02ec42cf9c8 27
donatien 3:e02ec42cf9c8 28 #ifndef NETSERVICE_H
donatien 3:e02ec42cf9c8 29 #define NETSERVICE_H
donatien 3:e02ec42cf9c8 30
donatien 3:e02ec42cf9c8 31 #include <list>
donatien 3:e02ec42cf9c8 32 using std::list;
donatien 3:e02ec42cf9c8 33
donatien 3:e02ec42cf9c8 34 ///Net Service base class
donatien 3:e02ec42cf9c8 35 /**
donatien 3:e02ec42cf9c8 36 Each connection-oriented object can register as service (by inheriting this class), so that it is polled regularly.
donatien 3:e02ec42cf9c8 37 It notifies the pool when the connection is terminated so that it can be destroyed.
donatien 3:e02ec42cf9c8 38 */
donatien 3:e02ec42cf9c8 39 class NetService
donatien 3:e02ec42cf9c8 40 {
donatien 3:e02ec42cf9c8 41 public:
donatien 3:e02ec42cf9c8 42 ///Instantiates a new service
donatien 3:e02ec42cf9c8 43 /**
donatien 3:e02ec42cf9c8 44 @param owned If true the object is owned by the pool and will be destroyed on closure.
donatien 3:e02ec42cf9c8 45 */
donatien 3:e02ec42cf9c8 46 NetService(bool owned = true); //Is owned by the pool?
donatien 3:e02ec42cf9c8 47 virtual ~NetService();
donatien 3:e02ec42cf9c8 48
donatien 3:e02ec42cf9c8 49 ///This method can be inherited so that it is called on each @a Net::poll() call.
donatien 3:e02ec42cf9c8 50 virtual void poll();
donatien 3:e02ec42cf9c8 51
donatien 3:e02ec42cf9c8 52 static void servicesPoll(); //Poll all registered services & destroy closed ones
donatien 3:e02ec42cf9c8 53
donatien 3:e02ec42cf9c8 54 protected:
donatien 3:e02ec42cf9c8 55 ///This flags the service as to be destructed if owned by the pool.
donatien 3:e02ec42cf9c8 56 void close();
donatien 3:e02ec42cf9c8 57
donatien 3:e02ec42cf9c8 58 private:
donatien 3:e02ec42cf9c8 59 bool m_closed;
donatien 3:e02ec42cf9c8 60 bool m_removed;
donatien 3:e02ec42cf9c8 61 bool m_owned;
donatien 3:e02ec42cf9c8 62
donatien 3:e02ec42cf9c8 63 static list<NetService*>& lpServices(); //Helper to prevent static initialization fiasco
donatien 3:e02ec42cf9c8 64
donatien 3:e02ec42cf9c8 65 };
donatien 3:e02ec42cf9c8 66
donatien 3:e02ec42cf9c8 67 #endif