NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

Committer:
donatien
Date:
Thu Aug 05 15:01:33 2010 +0000
Revision:
11:da4498f591ee
Parent:
10:d098e9192450

        

Who changed what in which revision?

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