lpc1768

Committer:
jh1cdv00
Date:
Tue Jan 27 01:38:19 2015 +0000
Revision:
0:f35dada1dac1
lpc1768

Who changed what in which revision?

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