ZG2100 Network interface source

Committer:
donatien
Date:
Fri Aug 06 10:46:03 2010 +0000
Revision:
4:e00281c7453d
Parent:
1:3a7c15057192

        

Who changed what in which revision?

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