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