1 #ifndef UPNP_TV_CTRLPT_H 2 #define UPNP_TV_CTRLPT_H 3 4 /************************************************************************** 5 * 6 * Copyright (c) 2000-2003 Intel Corporation 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions are met: 11 * 12 * - Redistributions of source code must retain the above copyright notice, 13 * this list of conditions and the following disclaimer. 14 * - Redistributions in binary form must reproduce the above copyright notice, 15 * this list of conditions and the following disclaimer in the documentation 16 * and/or other materials provided with the distribution. 17 * - Neither name of Intel Corporation nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 29 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 **************************************************************************/ 34 35 /*! 36 * \addtogroup UpnpSamples 37 * 38 * @{ 39 * 40 * \name Contro Point Sample API 41 * 42 * @{ 43 * 44 * \file 45 */ 46 47 #ifdef __cplusplus 48 extern "C" { 49 #endif 50 51 #include "sample_util.h" 52 53 #include "upnp.h" 54 #include "UpnpString.h" 55 #include "upnptools.h" 56 57 #include <signal.h> 58 #include <stdarg.h> 59 #include <stdio.h> 60 61 #define TV_SERVICE_SERVCOUNT 2 62 #define TV_SERVICE_CONTROL 0 63 #define TV_SERVICE_PICTURE 1 64 65 #define TV_CONTROL_VARCOUNT 3 66 #define TV_CONTROL_POWER 0 67 #define TV_CONTROL_CHANNEL 1 68 #define TV_CONTROL_VOLUME 2 69 70 #define TV_PICTURE_VARCOUNT 4 71 #define TV_PICTURE_COLOR 0 72 #define TV_PICTURE_TINT 1 73 #define TV_PICTURE_CONTRAST 2 74 #define TV_PICTURE_BRIGHTNESS 3 75 76 #define TV_MAX_VAL_LEN 5 77 78 #define TV_SUCCESS 0 79 #define TV_ERROR (-1) 80 #define TV_WARNING 1 81 82 /* This should be the maximum VARCOUNT from above */ 83 #define TV_MAXVARS TV_PICTURE_VARCOUNT 84 85 extern const char *TvServiceName[]; 86 extern const char *TvVarName[TV_SERVICE_SERVCOUNT][TV_MAXVARS]; 87 extern char TvVarCount[]; 88 89 struct tv_service { 90 char ServiceId[NAME_SIZE]; 91 char ServiceType[NAME_SIZE]; 92 char *VariableStrVal[TV_MAXVARS]; 93 char EventURL[NAME_SIZE]; 94 char ControlURL[NAME_SIZE]; 95 char SID[NAME_SIZE]; 96 }; 97 98 extern struct TvDeviceNode *GlobalDeviceList; 99 100 struct TvDevice { 101 char UDN[250]; 102 char DescDocURL[250]; 103 char FriendlyName[250]; 104 char PresURL[250]; 105 int AdvrTimeOut; 106 struct tv_service TvService[TV_SERVICE_SERVCOUNT]; 107 }; 108 109 struct TvDeviceNode { 110 struct TvDevice device; 111 struct TvDeviceNode *next; 112 }; 113 114 extern ithread_mutex_t DeviceListMutex; 115 116 extern UpnpClient_Handle ctrlpt_handle; 117 118 void TvCtrlPointPrintHelp(void); 119 int TvCtrlPointDeleteNode(struct TvDeviceNode *); 120 int TvCtrlPointRemoveDevice(const char *); 121 int TvCtrlPointRemoveAll(void); 122 int TvCtrlPointRefresh(void); 123 124 int TvCtrlPointSendAction(int, int, const char *, const char **, char **, int); 125 int TvCtrlPointSendActionNumericArg(int devnum, int service, const char *actionName, const char *paramName, int paramValue); 126 int TvCtrlPointSendPowerOn(int devnum); 127 int TvCtrlPointSendPowerOff(int devnum); 128 int TvCtrlPointSendSetChannel(int, int); 129 int TvCtrlPointSendSetVolume(int, int); 130 int TvCtrlPointSendSetColor(int, int); 131 int TvCtrlPointSendSetTint(int, int); 132 int TvCtrlPointSendSetContrast(int, int); 133 int TvCtrlPointSendSetBrightness(int, int); 134 135 int TvCtrlPointGetVar(int, int, const char *); 136 int TvCtrlPointGetPower(int devnum); 137 int TvCtrlPointGetChannel(int); 138 int TvCtrlPointGetVolume(int); 139 int TvCtrlPointGetColor(int); 140 int TvCtrlPointGetTint(int); 141 int TvCtrlPointGetContrast(int); 142 int TvCtrlPointGetBrightness(int); 143 144 int TvCtrlPointGetDevice(int, struct TvDeviceNode **); 145 int TvCtrlPointPrintList(void); 146 int TvCtrlPointPrintDevice(int); 147 void TvCtrlPointAddDevice(IXML_Document *, const char *, int); 148 void TvCtrlPointHandleGetVar(const char *, const char *, const DOMString); 149 150 /*! 151 * \brief Update a Tv state table. Called when an event is received. 152 * 153 * Note: this function is NOT thread save. It must be called from another 154 * function that has locked the global device list. 155 **/ 156 void TvStateUpdate( 157 /*! [in] The UDN of the parent device. */ 158 char *UDN, 159 /*! [in] The service state table to update. */ 160 int Service, 161 /*! [out] DOM document representing the XML received with the event. */ 162 IXML_Document *ChangedVariables, 163 /*! [out] pointer to the state table for the Tv service to update. */ 164 char **State); 165 166 void TvCtrlPointHandleEvent(const char *, int, IXML_Document *); 167 void TvCtrlPointHandleSubscribeUpdate(const char *, const Upnp_SID, int); 168 int TvCtrlPointCallbackEventHandler(Upnp_EventType, const void *, void *); 169 170 /*! 171 * \brief Checks the advertisement each device in the global device list. 172 * 173 * If an advertisement expires, the device is removed from the list. 174 * 175 * If an advertisement is about to expire, a search request is sent for that 176 * device. 177 */ 178 void TvCtrlPointVerifyTimeouts( 179 /*! [in] The increment to subtract from the timeouts each time the 180 * function is called. */ 181 int incr); 182 183 void TvCtrlPointPrintCommands(void); 184 void* TvCtrlPointCommandLoop(void *); 185 int TvCtrlPointStart(char* iface, state_update updateFunctionPtr, int combo); 186 int TvCtrlPointStop(void); 187 int TvCtrlPointProcessCommand(char *cmdline); 188 189 /*! 190 * \brief Print help info for this application. 191 */ 192 void TvCtrlPointPrintShortHelp(void); 193 194 /*! 195 * \brief Print long help info for this application. 196 */ 197 void TvCtrlPointPrintLongHelp(void); 198 199 /*! 200 * \briefPrint the list of valid command line commands to the user 201 */ 202 void TvCtrlPointPrintCommands(void); 203 204 /*! 205 * \brief Function that receives commands from the user at the command prompt 206 * during the lifetime of the device, and calls the appropriate 207 * functions for those commands. 208 */ 209 void *TvCtrlPointCommandLoop(void *args); 210 211 /*! 212 * \brief 213 */ 214 int TvCtrlPointProcessCommand(char *cmdline); 215 216 #ifdef __cplusplus 217 }; 218 #endif 219 220 221 /*! @} Device Sample */ 222 223 /*! @} UpnpSamples */ 224 225 #endif /* UPNP_TV_CTRLPT_H */ 226