Committer:
mbed714
Date:
Sat Sep 18 23:05:49 2010 +0000
Revision:
0:d616ece2d859

        

Who changed what in which revision?

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