Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

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