Committer:
zoot661
Date:
Tue May 29 09:49:18 2012 +0000
Revision:
0:f993b6d8b1d8

        

Who changed what in which revision?

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