XOOMの動作状況を聞き処理を変えてみました。 USBケーブルを抜いた際に処理を終了するようにしました。

Dependencies:   mbed

Committer:
abe00makoto
Date:
Fri May 27 18:51:15 2011 +0000
Revision:
3:432e5675d240
Parent:
0:9fb6c423e32c
nexus one support
maybe support add XOOM ,nexus S

Who changed what in which revision?

UserRevisionLine numberNew contents of line
abe00makoto 0:9fb6c423e32c 1 /*
abe00makoto 0:9fb6c423e32c 2 Copyright (c) 2010 Peter Barrett
abe00makoto 0:9fb6c423e32c 3
abe00makoto 0:9fb6c423e32c 4 Permission is hereby granted, free of charge, to any person obtaining a copy
abe00makoto 0:9fb6c423e32c 5 of this software and associated documentation files (the "Software"), to deal
abe00makoto 0:9fb6c423e32c 6 in the Software without restriction, including without limitation the rights
abe00makoto 0:9fb6c423e32c 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
abe00makoto 0:9fb6c423e32c 8 copies of the Software, and to permit persons to whom the Software is
abe00makoto 0:9fb6c423e32c 9 furnished to do so, subject to the following conditions:
abe00makoto 0:9fb6c423e32c 10
abe00makoto 0:9fb6c423e32c 11 The above copyright notice and this permission notice shall be included in
abe00makoto 0:9fb6c423e32c 12 all copies or substantial portions of the Software.
abe00makoto 0:9fb6c423e32c 13
abe00makoto 0:9fb6c423e32c 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
abe00makoto 0:9fb6c423e32c 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
abe00makoto 0:9fb6c423e32c 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
abe00makoto 0:9fb6c423e32c 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
abe00makoto 0:9fb6c423e32c 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
abe00makoto 0:9fb6c423e32c 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
abe00makoto 0:9fb6c423e32c 20 THE SOFTWARE.
abe00makoto 0:9fb6c423e32c 21 */
abe00makoto 0:9fb6c423e32c 22
abe00makoto 0:9fb6c423e32c 23 /*
abe00makoto 0:9fb6c423e32c 24 Tue Apr 26 2011 Bart Janssens: added a socket listener
abe00makoto 0:9fb6c423e32c 25 */
abe00makoto 0:9fb6c423e32c 26
abe00makoto 0:9fb6c423e32c 27 #ifndef SOCKET_H_INCLUDED
abe00makoto 0:9fb6c423e32c 28 #define SOCKET_H_INCLUDED
abe00makoto 0:9fb6c423e32c 29
abe00makoto 0:9fb6c423e32c 30 #define SOCKET_HCI 1
abe00makoto 0:9fb6c423e32c 31 #define SOCKET_L2CAP 2
abe00makoto 0:9fb6c423e32c 32 #define SOCKET_RFCOM 3
abe00makoto 0:9fb6c423e32c 33
abe00makoto 0:9fb6c423e32c 34 typedef struct
abe00makoto 0:9fb6c423e32c 35 {
abe00makoto 0:9fb6c423e32c 36 u8 AddressSpecific[0]; // BDADDR,psm etc
abe00makoto 0:9fb6c423e32c 37 } SocketAddrHdr;
abe00makoto 0:9fb6c423e32c 38
abe00makoto 0:9fb6c423e32c 39
abe00makoto 0:9fb6c423e32c 40
abe00makoto 0:9fb6c423e32c 41 enum SocketState
abe00makoto 0:9fb6c423e32c 42 {
abe00makoto 0:9fb6c423e32c 43 SocketState_Unknown,
abe00makoto 0:9fb6c423e32c 44 SocketState_Opening,
abe00makoto 0:9fb6c423e32c 45 SocketState_Open,
abe00makoto 0:9fb6c423e32c 46 SocketState_Closing,
abe00makoto 0:9fb6c423e32c 47 SocketState_Closed,
abe00makoto 0:9fb6c423e32c 48 SocketState_Listen,
abe00makoto 0:9fb6c423e32c 49 SocketState_Accept
abe00makoto 0:9fb6c423e32c 50 };
abe00makoto 0:9fb6c423e32c 51
abe00makoto 0:9fb6c423e32c 52 typedef void (*SocketCallback)(int socket, SocketState state, const u8* data, int len, void* userData);
abe00makoto 0:9fb6c423e32c 53
abe00makoto 0:9fb6c423e32c 54 class SocketListener
abe00makoto 0:9fb6c423e32c 55 {
abe00makoto 0:9fb6c423e32c 56 public:
abe00makoto 0:9fb6c423e32c 57 int ID;
abe00makoto 0:9fb6c423e32c 58 int Type;
abe00makoto 0:9fb6c423e32c 59 int port;
abe00makoto 0:9fb6c423e32c 60 SocketCallback Callback;
abe00makoto 0:9fb6c423e32c 61 void* userData;
abe00makoto 0:9fb6c423e32c 62 };
abe00makoto 0:9fb6c423e32c 63
abe00makoto 0:9fb6c423e32c 64 //===========================================================================
abe00makoto 0:9fb6c423e32c 65 //===========================================================================
abe00makoto 0:9fb6c423e32c 66 // Don't need to look at or use anything below this line:
abe00makoto 0:9fb6c423e32c 67 // Internal representation of socket
abe00makoto 0:9fb6c423e32c 68
abe00makoto 0:9fb6c423e32c 69 class SocketHandler;
abe00makoto 0:9fb6c423e32c 70 class SocketInternal
abe00makoto 0:9fb6c423e32c 71 {
abe00makoto 0:9fb6c423e32c 72 public:
abe00makoto 0:9fb6c423e32c 73
abe00makoto 0:9fb6c423e32c 74 u8 ID;
abe00makoto 0:9fb6c423e32c 75 u8 State;
abe00makoto 0:9fb6c423e32c 76 u8 Type;
abe00makoto 0:9fb6c423e32c 77 u8 B0;
abe00makoto 0:9fb6c423e32c 78 int port;
abe00makoto 0:9fb6c423e32c 79 SocketCallback Callback;
abe00makoto 0:9fb6c423e32c 80 void* userData;
abe00makoto 0:9fb6c423e32c 81 u8 Data[0]; // Extra socket data starts here
abe00makoto 0:9fb6c423e32c 82
abe00makoto 0:9fb6c423e32c 83 void Recv(const u8* data, int len)
abe00makoto 0:9fb6c423e32c 84 {
abe00makoto 0:9fb6c423e32c 85 Callback(ID,(SocketState)State,data,len,userData);
abe00makoto 0:9fb6c423e32c 86 }
abe00makoto 0:9fb6c423e32c 87
abe00makoto 0:9fb6c423e32c 88 void SetState(SocketState state)
abe00makoto 0:9fb6c423e32c 89 {
abe00makoto 0:9fb6c423e32c 90 State = state;
abe00makoto 0:9fb6c423e32c 91 Callback(ID,(SocketState)State,0,0,userData);
abe00makoto 0:9fb6c423e32c 92 }
abe00makoto 0:9fb6c423e32c 93 };
abe00makoto 0:9fb6c423e32c 94
abe00makoto 0:9fb6c423e32c 95 class SocketHandler
abe00makoto 0:9fb6c423e32c 96 {
abe00makoto 0:9fb6c423e32c 97 public:
abe00makoto 0:9fb6c423e32c 98 virtual int Open(SocketInternal* sock, SocketAddrHdr* addr) = 0;
abe00makoto 0:9fb6c423e32c 99 virtual int Create(SocketInternal* sock, SocketAddrHdr* addr) = 0;
abe00makoto 0:9fb6c423e32c 100 virtual int Send(SocketInternal* sock, const u8* data, int len) = 0;
abe00makoto 0:9fb6c423e32c 101 virtual int Close(SocketInternal* sock) = 0;
abe00makoto 0:9fb6c423e32c 102 virtual int Accept(SocketInternal* sock, SocketAddrHdr* addr) = 0;
abe00makoto 0:9fb6c423e32c 103 };
abe00makoto 0:9fb6c423e32c 104
abe00makoto 0:9fb6c423e32c 105 int RegisterSocketHandler(int type, SocketHandler* handler);
abe00makoto 0:9fb6c423e32c 106 SocketInternal* GetSocketInternal(int socket);
abe00makoto 0:9fb6c423e32c 107
abe00makoto 0:9fb6c423e32c 108 int Socket_Open(int type, SocketAddrHdr* addr, SocketCallback callback, void* userData); // Open a socket
abe00makoto 0:9fb6c423e32c 109 int Socket_Listen(int type, int port,SocketCallback callback, void* userData);
abe00makoto 0:9fb6c423e32c 110 int Socket_InUse(int type, int port);
abe00makoto 0:9fb6c423e32c 111 int Socket_Accept(int socket, SocketCallback callback, void* userData);
abe00makoto 0:9fb6c423e32c 112 SocketInternal* Socket_Create(int type,SocketAddrHdr* addr, int port);
abe00makoto 0:9fb6c423e32c 113 int Socket_Send(int socket, const u8* data, int len);
abe00makoto 0:9fb6c423e32c 114 int Socket_State(int socket);
abe00makoto 0:9fb6c423e32c 115 int Socket_Close(int socket);
abe00makoto 0:9fb6c423e32c 116
abe00makoto 0:9fb6c423e32c 117 #define ERR_SOCKET_TYPE_NOT_FOUND -200
abe00makoto 0:9fb6c423e32c 118 #define ERR_SOCKET_NOT_FOUND -201
abe00makoto 0:9fb6c423e32c 119 #define ERR_SOCKET_NONE_LEFT -202
abe00makoto 0:9fb6c423e32c 120 #define ERR_SOCKET_IN_USE -203
abe00makoto 0:9fb6c423e32c 121
abe00makoto 0:9fb6c423e32c 122 #endif // SOCKET_H_INCLUDED