Hi. This is the feed program for Cosm. (The previous name of the services is Pachube.)

Dependencies:   mbed ThermistorPack Pachube ConfigFile EthernetNetIf TextLCD HTTPClient_ToBeRemoved FatFileSystem SDFileSystem

Committer:
shintamainjp
Date:
Mon Aug 06 12:37:59 2012 +0000
Revision:
0:521ba375aa0f
Pachube renamed to Cosm.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shintamainjp 0:521ba375aa0f 1
shintamainjp 0:521ba375aa0f 2 /*
shintamainjp 0:521ba375aa0f 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
shintamainjp 0:521ba375aa0f 4
shintamainjp 0:521ba375aa0f 5 Permission is hereby granted, free of charge, to any person obtaining a copy
shintamainjp 0:521ba375aa0f 6 of this software and associated documentation files (the "Software"), to deal
shintamainjp 0:521ba375aa0f 7 in the Software without restriction, including without limitation the rights
shintamainjp 0:521ba375aa0f 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
shintamainjp 0:521ba375aa0f 9 copies of the Software, and to permit persons to whom the Software is
shintamainjp 0:521ba375aa0f 10 furnished to do so, subject to the following conditions:
shintamainjp 0:521ba375aa0f 11
shintamainjp 0:521ba375aa0f 12 The above copyright notice and this permission notice shall be included in
shintamainjp 0:521ba375aa0f 13 all copies or substantial portions of the Software.
shintamainjp 0:521ba375aa0f 14
shintamainjp 0:521ba375aa0f 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
shintamainjp 0:521ba375aa0f 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
shintamainjp 0:521ba375aa0f 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
shintamainjp 0:521ba375aa0f 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
shintamainjp 0:521ba375aa0f 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
shintamainjp 0:521ba375aa0f 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
shintamainjp 0:521ba375aa0f 21 THE SOFTWARE.
shintamainjp 0:521ba375aa0f 22 */
shintamainjp 0:521ba375aa0f 23
shintamainjp 0:521ba375aa0f 24 /** \file
shintamainjp 0:521ba375aa0f 25 TCP Socket header file
shintamainjp 0:521ba375aa0f 26 */
shintamainjp 0:521ba375aa0f 27
shintamainjp 0:521ba375aa0f 28 #ifndef TCPSOCKET_H
shintamainjp 0:521ba375aa0f 29 #define TCPSOCKET_H
shintamainjp 0:521ba375aa0f 30
shintamainjp 0:521ba375aa0f 31 #include "core/net.h"
shintamainjp 0:521ba375aa0f 32 #include "core/host.h"
shintamainjp 0:521ba375aa0f 33 //Essentially it is a safe interface to NetTcpSocket
shintamainjp 0:521ba375aa0f 34
shintamainjp 0:521ba375aa0f 35 ///TCP Socket error codes
shintamainjp 0:521ba375aa0f 36 enum TCPSocketErr
shintamainjp 0:521ba375aa0f 37 {
shintamainjp 0:521ba375aa0f 38 __TCPSOCKET_MIN = -0xFFFF,
shintamainjp 0:521ba375aa0f 39 TCPSOCKET_SETUP, ///<TCPSocket not properly configured
shintamainjp 0:521ba375aa0f 40 TCPSOCKET_TIMEOUT, ///<Connection timed out
shintamainjp 0:521ba375aa0f 41 TCPSOCKET_IF, ///<Interface has problems, does not exist or is not initialized
shintamainjp 0:521ba375aa0f 42 TCPSOCKET_MEM, ///<Not enough mem
shintamainjp 0:521ba375aa0f 43 TCPSOCKET_INUSE, ///<Interface / Port is in use
shintamainjp 0:521ba375aa0f 44 TCPSOCKET_EMPTY, ///<Connections queue is empty
shintamainjp 0:521ba375aa0f 45 TCPSOCKET_RST, ///<Connection was reset by remote host
shintamainjp 0:521ba375aa0f 46 //...
shintamainjp 0:521ba375aa0f 47 TCPSOCKET_OK = 0 ///<Success
shintamainjp 0:521ba375aa0f 48 };
shintamainjp 0:521ba375aa0f 49
shintamainjp 0:521ba375aa0f 50 ///TCP Socket Events
shintamainjp 0:521ba375aa0f 51 enum TCPSocketEvent
shintamainjp 0:521ba375aa0f 52 {
shintamainjp 0:521ba375aa0f 53 TCPSOCKET_CONNECTED, ///<Connected to host
shintamainjp 0:521ba375aa0f 54 TCPSOCKET_ACCEPT, ///<Client is connected, must call accept() to get a new Socket
shintamainjp 0:521ba375aa0f 55 TCPSOCKET_READABLE, ///<Data in buf
shintamainjp 0:521ba375aa0f 56 TCPSOCKET_WRITEABLE, ///<Can write data to buf
shintamainjp 0:521ba375aa0f 57 TCPSOCKET_CONTIMEOUT, ///<Connection timed out
shintamainjp 0:521ba375aa0f 58 TCPSOCKET_CONRST, ///<Connection was reset by remote host
shintamainjp 0:521ba375aa0f 59 TCPSOCKET_CONABRT, ///<Connection was aborted
shintamainjp 0:521ba375aa0f 60 TCPSOCKET_ERROR, ///<Unknown error
shintamainjp 0:521ba375aa0f 61 TCPSOCKET_DISCONNECTED ///<Disconnected
shintamainjp 0:521ba375aa0f 62 };
shintamainjp 0:521ba375aa0f 63
shintamainjp 0:521ba375aa0f 64 class NetTcpSocket;
shintamainjp 0:521ba375aa0f 65 enum NetTcpSocketEvent;
shintamainjp 0:521ba375aa0f 66
shintamainjp 0:521ba375aa0f 67 ///This is a simple TCP Socket class
shintamainjp 0:521ba375aa0f 68 /**
shintamainjp 0:521ba375aa0f 69 This class exposes an API to deal with TCP Sockets
shintamainjp 0:521ba375aa0f 70 */
shintamainjp 0:521ba375aa0f 71 class TCPSocket
shintamainjp 0:521ba375aa0f 72 {
shintamainjp 0:521ba375aa0f 73 public:
shintamainjp 0:521ba375aa0f 74 ///Creates a new socket
shintamainjp 0:521ba375aa0f 75 TCPSocket();
shintamainjp 0:521ba375aa0f 76 protected:
shintamainjp 0:521ba375aa0f 77 TCPSocket(NetTcpSocket* pNetTcpSocket);
shintamainjp 0:521ba375aa0f 78 public:
shintamainjp 0:521ba375aa0f 79 ///Closes if needed and destroys the socket
shintamainjp 0:521ba375aa0f 80 ~TCPSocket(); //close()
shintamainjp 0:521ba375aa0f 81
shintamainjp 0:521ba375aa0f 82 ///Binds the socket to (local) host
shintamainjp 0:521ba375aa0f 83 TCPSocketErr bind(const Host& me);
shintamainjp 0:521ba375aa0f 84
shintamainjp 0:521ba375aa0f 85 ///Starts listening
shintamainjp 0:521ba375aa0f 86 TCPSocketErr listen();
shintamainjp 0:521ba375aa0f 87
shintamainjp 0:521ba375aa0f 88 ///Connects socket to host
shintamainjp 0:521ba375aa0f 89 TCPSocketErr connect(const Host& host);
shintamainjp 0:521ba375aa0f 90
shintamainjp 0:521ba375aa0f 91 ///Accepts connection from client and gets connected socket
shintamainjp 0:521ba375aa0f 92 TCPSocketErr accept(Host* pClient, TCPSocket** ppNewTcpSocket);
shintamainjp 0:521ba375aa0f 93
shintamainjp 0:521ba375aa0f 94 ///Sends data
shintamainjp 0:521ba375aa0f 95 /*
shintamainjp 0:521ba375aa0f 96 @return a negative error code or the number of bytes transmitted
shintamainjp 0:521ba375aa0f 97 */
shintamainjp 0:521ba375aa0f 98 int /*if < 0 : TCPSocketErr*/ send(const char* buf, int len);
shintamainjp 0:521ba375aa0f 99
shintamainjp 0:521ba375aa0f 100 ///Receives data
shintamainjp 0:521ba375aa0f 101 /*
shintamainjp 0:521ba375aa0f 102 @return a negative error code or the number of bytes received
shintamainjp 0:521ba375aa0f 103 */
shintamainjp 0:521ba375aa0f 104 int /*if < 0 : TCPSocketErr*/ recv(char* buf, int len);
shintamainjp 0:521ba375aa0f 105
shintamainjp 0:521ba375aa0f 106 /* TODO NTH : printf / scanf helpers that call send/recv */
shintamainjp 0:521ba375aa0f 107
shintamainjp 0:521ba375aa0f 108 ///Closes socket
shintamainjp 0:521ba375aa0f 109 TCPSocketErr close();
shintamainjp 0:521ba375aa0f 110
shintamainjp 0:521ba375aa0f 111 //Callbacks
shintamainjp 0:521ba375aa0f 112 ///Setups callback
shintamainjp 0:521ba375aa0f 113 /**
shintamainjp 0:521ba375aa0f 114 @param pMethod : callback function
shintamainjp 0:521ba375aa0f 115 */
shintamainjp 0:521ba375aa0f 116 void setOnEvent( void (*pMethod)(TCPSocketEvent) );
shintamainjp 0:521ba375aa0f 117
shintamainjp 0:521ba375aa0f 118 class CDummy;
shintamainjp 0:521ba375aa0f 119 ///Setups callback
shintamainjp 0:521ba375aa0f 120 /**
shintamainjp 0:521ba375aa0f 121 @param pItem : instance of class on which to execute the callback method
shintamainjp 0:521ba375aa0f 122 @param pMethod : callback method
shintamainjp 0:521ba375aa0f 123 */
shintamainjp 0:521ba375aa0f 124 template<class T>
shintamainjp 0:521ba375aa0f 125 void setOnEvent( T* pItem, void (T::*pMethod)(TCPSocketEvent) )
shintamainjp 0:521ba375aa0f 126 {
shintamainjp 0:521ba375aa0f 127 m_pCbItem = (CDummy*) pItem;
shintamainjp 0:521ba375aa0f 128 m_pCbMeth = (void (CDummy::*)(TCPSocketEvent)) pMethod;
shintamainjp 0:521ba375aa0f 129 }
shintamainjp 0:521ba375aa0f 130
shintamainjp 0:521ba375aa0f 131 ///Disables callback
shintamainjp 0:521ba375aa0f 132 void resetOnEvent();
shintamainjp 0:521ba375aa0f 133
shintamainjp 0:521ba375aa0f 134 protected:
shintamainjp 0:521ba375aa0f 135 void onNetTcpSocketEvent(NetTcpSocketEvent e);
shintamainjp 0:521ba375aa0f 136 TCPSocketErr checkInst();
shintamainjp 0:521ba375aa0f 137
shintamainjp 0:521ba375aa0f 138 private:
shintamainjp 0:521ba375aa0f 139 NetTcpSocket* m_pNetTcpSocket;
shintamainjp 0:521ba375aa0f 140
shintamainjp 0:521ba375aa0f 141 CDummy* m_pCbItem;
shintamainjp 0:521ba375aa0f 142 void (CDummy::*m_pCbMeth)(TCPSocketEvent);
shintamainjp 0:521ba375aa0f 143
shintamainjp 0:521ba375aa0f 144 void (*m_pCb)(TCPSocketEvent);
shintamainjp 0:521ba375aa0f 145
shintamainjp 0:521ba375aa0f 146 };
shintamainjp 0:521ba375aa0f 147
shintamainjp 0:521ba375aa0f 148 #endif