Host library for controlling a WiConnect enabled Wi-Fi module.
Dependents: wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more
SocketIrqHandlerMap.h
00001 /** 00002 * ACKme WiConnect Host Library is licensed under the BSD licence: 00003 * 00004 * Copyright (c)2014 ACKme Networks. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without modification, 00008 * are permitted provided that the following conditions are met: 00009 * 00010 * 1. Redistributions of source code must retain the above copyright notice, 00011 * this list of conditions and the following disclaimer. 00012 * 2. Redistributions in binary form must reproduce the above copyright notice, 00013 * this list of conditions and the following disclaimer in the documentation 00014 * and/or other materials provided with the distribution. 00015 * 3. The name of the author may not be used to endorse or promote products 00016 * derived from this software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED 00019 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00020 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00021 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00022 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00023 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00026 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00027 * OF SUCH DAMAGE. 00028 */ 00029 #pragma once 00030 00031 #include "Wiconnect.h" 00032 #include "PinIrqHandler.h" 00033 00034 namespace wiconnect 00035 { 00036 00037 /** 00038 * Generic callback function. 00039 * 00040 * @note Internal use only. 00041 */ 00042 class SocketIrqHandlerMap 00043 { 00044 public: 00045 /*************************************************************************************************/ 00046 SocketIrqHandlerMap() 00047 { 00048 memset(handlers, 0, sizeof(handlers)); 00049 } 00050 00051 /*************************************************************************************************/ 00052 ~SocketIrqHandlerMap() 00053 { 00054 for(int i = 0; i < WICONNECT_MAX_PIN_IRQ_HANDLERS; ++i) 00055 { 00056 if(handlers[i] != NULL) 00057 { 00058 handlers[i]->~PinIrqHandler(); 00059 } 00060 } 00061 } 00062 00063 /*************************************************************************************************/ 00064 bool pinIsRegistered(Pin pin) 00065 { 00066 for(int i = 0; i < WICONNECT_MAX_PIN_IRQ_HANDLERS; ++i) 00067 { 00068 if(handlers[i] != NULL && handlers[i]->irqPin == pin) 00069 { 00070 return true; 00071 } 00072 } 00073 return false; 00074 } 00075 00076 /*************************************************************************************************/ 00077 WiconnectResult registerHandler(Pin pin, const Callback &callback) 00078 { 00079 if(pinIsRegistered(pin)) 00080 { 00081 return WICONNECT_DUPLICATE; 00082 } 00083 00084 PinIrqHandler *handler = NULL; 00085 00086 for(int i = 0; i < WICONNECT_MAX_PIN_IRQ_HANDLERS; ++i) 00087 { 00088 if(handlers[i] == NULL) 00089 { 00090 handler = (PinIrqHandler*)&handlerBuffers[i]; 00091 handlers[i] = handler; 00092 } 00093 } 00094 00095 if(handler == NULL) 00096 { 00097 return WICONNECT_NOT_FOUND; 00098 } 00099 00100 *handler = PinIrqHandler(pin, callback); 00101 00102 return WICONNECT_SUCCESS; 00103 } 00104 00105 /*************************************************************************************************/ 00106 WiconnectResult unregisterHandler(Pin pin) 00107 { 00108 for(int i = 0; i < WICONNECT_MAX_PIN_IRQ_HANDLERS; ++i) 00109 { 00110 if(handlers[i] != NULL && handlers[i]->irqPin == pin) 00111 { 00112 handlers[i]->~PinIrqHandler(); 00113 handlers[i] = NULL; 00114 return WICONNECT_SUCCESS; 00115 } 00116 } 00117 00118 return WICONNECT_NOT_FOUND; 00119 } 00120 00121 private: 00122 PinIrqHandler *handlers[WICONNECT_MAX_PIN_IRQ_HANDLERS]; 00123 PinIrqHandlerBuffer handlerBuffers[WICONNECT_MAX_PIN_IRQ_HANDLERS]; 00124 }; 00125 00126 00127 00128 }
Generated on Tue Jul 12 2022 17:35:58 by 1.7.2