hattori&ide

Dependencies:   mbed

Committer:
hattori_atsushi
Date:
Sun Dec 18 08:16:01 2022 +0000
Revision:
0:f77369cabd75
hattori

Who changed what in which revision?

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