00001 /************************************************************************** 00002 * 00003 * Copyright (c) 2000-2003 Intel Corporation 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * - Redistributions of source code must retain the above copyright notice, 00010 * this list of conditions and the following disclaimer. 00011 * - Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * - Neither name of Intel Corporation nor the names of its contributors 00015 * may be used to endorse or promote products derived from this software 00016 * without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00019 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00020 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00021 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 00022 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00023 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00024 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00025 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00026 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00027 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 **************************************************************************/ 00031 00032 00033 #ifndef UPNP_TV_DEVICE_H 00034 #define UPNP_TV_DEVICE_H 00035 00036 00037 #include <stdio.h> 00038 #include <signal.h> 00039 00040 00041 #ifdef __cplusplus 00042 extern "C" { 00043 #endif 00044 00045 00046 #include "sample_util.h" 00047 00048 00049 #include "ithread.h" 00050 #include "upnp.h" 00051 00052 00053 #include <stdlib.h> 00054 #include <string.h> 00055 00056 00057 #ifdef WIN32 00058 /* Do not #include <unistd.h> */ 00059 #else 00060 #include <unistd.h> 00061 #endif 00062 00063 00064 //Color constants 00065 #define MAX_COLOR 10 00066 #define MIN_COLOR 1 00067 00068 //Brightness constants 00069 #define MAX_BRIGHTNESS 10 00070 #define MIN_BRIGHTNESS 1 00071 00072 //Power constants 00073 #define POWER_ON 1 00074 #define POWER_OFF 0 00075 00076 //Tint constants 00077 #define MAX_TINT 10 00078 #define MIN_TINT 1 00079 00080 //Volume constants 00081 #define MAX_VOLUME 10 00082 #define MIN_VOLUME 1 00083 00084 //Contrast constants 00085 #define MAX_CONTRAST 10 00086 #define MIN_CONTRAST 1 00087 00088 //Channel constants 00089 #define MAX_CHANNEL 100 00090 #define MIN_CHANNEL 1 00091 00092 //Number of services. 00093 #define TV_SERVICE_SERVCOUNT 2 00094 00095 //Index of control service 00096 #define TV_SERVICE_CONTROL 0 00097 00098 //Index of picture service 00099 #define TV_SERVICE_PICTURE 1 00100 00101 //Number of control variables 00102 #define TV_CONTROL_VARCOUNT 3 00103 00104 //Index of power variable 00105 #define TV_CONTROL_POWER 0 00106 00107 //Index of channel variable 00108 #define TV_CONTROL_CHANNEL 1 00109 00110 //Index of volume variable 00111 #define TV_CONTROL_VOLUME 2 00112 00113 //Number of picture variables 00114 #define TV_PICTURE_VARCOUNT 4 00115 00116 //Index of color variable 00117 #define TV_PICTURE_COLOR 0 00118 00119 //Index of tint variable 00120 #define TV_PICTURE_TINT 1 00121 00122 //Index of contrast variable 00123 #define TV_PICTURE_CONTRAST 2 00124 00125 //Index of brightness variable 00126 #define TV_PICTURE_BRIGHTNESS 3 00127 00128 //Max value length 00129 #define TV_MAX_VAL_LEN 5 00130 00131 //Max actions 00132 #define TV_MAXACTIONS 12 00133 00134 /* This should be the maximum VARCOUNT from above */ 00135 #define TV_MAXVARS TV_PICTURE_VARCOUNT 00136 00137 00138 extern char TvDeviceType[]; 00139 00140 extern char *TvServiceType[]; 00141 00142 00143 00144 /****************************************************************************** 00145 * upnp_action 00146 * 00147 * Description: 00148 * Prototype for all actions. For each action that a service 00149 * implements, there is a corresponding function with this prototype. 00150 * Pointers to these functions, along with action names, are stored 00151 * in the service table. When an action request comes in the action 00152 * name is matched, and the appropriate function is called. 00153 * Each function returns UPNP_E_SUCCESS, on success, and a nonzero 00154 * error code on failure. 00155 * 00156 * Parameters: 00157 * 00158 * IXML_Document * request - document of action request 00159 * IXML_Document **out - action result 00160 * char **errorString - errorString (in case action was unsuccessful) 00161 * 00162 *****************************************************************************/ 00163 00164 typedef int (*upnp_action) (IXML_Document *request, IXML_Document **out, char **errorString); 00165 00166 /* Structure for storing Tv Service 00167 identifiers and state table */ 00168 struct TvService { 00169 00170 char UDN[NAME_SIZE]; /* Universally Unique Device Name */ 00171 char ServiceId[NAME_SIZE]; 00172 char ServiceType[NAME_SIZE]; 00173 char *VariableName[TV_MAXVARS]; 00174 char *VariableStrVal[TV_MAXVARS]; 00175 char *ActionNames[TV_MAXACTIONS]; 00176 upnp_action actions[TV_MAXACTIONS]; 00177 unsigned int VariableCount; 00178 }; 00179 00180 //Array of service structures 00181 extern struct TvService tv_service_table[]; 00182 00183 //Device handle returned from sdk 00184 extern UpnpDevice_Handle device_handle; 00185 00186 00187 /* Mutex for protecting the global state table data 00188 in a multi-threaded, asynchronous environment. 00189 All functions should lock this mutex before reading 00190 or writing the state table data. */ 00191 extern ithread_mutex_t TVDevMutex; 00192 00193 00194 00195 /****************************************************************************** 00196 * SetActionTable 00197 * 00198 * Description: 00199 * Initializes the action table for the specified service. 00200 * Note that 00201 * knowledge of the service description is 00202 * assumed. Action names are hardcoded. 00203 * Parameters: 00204 * int serviceType - one of TV_SERVICE_CONTROL or, TV_SERVICE_PICTURE 00205 * struct TvService *out - service containing action table to set. 00206 * 00207 *****************************************************************************/ 00208 int SetActionTable(int serviceType, struct TvService *out); 00209 00210 /****************************************************************************** 00211 * TvDeviceStateTableInit 00212 * 00213 * Description: 00214 * Initialize the device state table for 00215 * this TvDevice, pulling identifier info 00216 * from the description Document. Note that 00217 * knowledge of the service description is 00218 * assumed. State table variables and default 00219 * values are currently hardcoded in this file 00220 * rather than being read from service description 00221 * documents. 00222 * 00223 * Parameters: 00224 * DescDocURL -- The description document URL 00225 * 00226 *****************************************************************************/ 00227 int TvDeviceStateTableInit(char*); 00228 00229 00230 /****************************************************************************** 00231 * TvDeviceHandleSubscriptionRequest 00232 * 00233 * Description: 00234 * Called during a subscription request callback. If the 00235 * subscription request is for this device and either its 00236 * control service or picture service, then accept it. 00237 * 00238 * Parameters: 00239 * sr_event -- The subscription request event structure 00240 * 00241 *****************************************************************************/ 00242 int TvDeviceHandleSubscriptionRequest(const UpnpSubscriptionRequest *); 00243 00244 /****************************************************************************** 00245 * TvDeviceHandleGetVarRequest 00246 * 00247 * Description: 00248 * Called during a get variable request callback. If the 00249 * request is for this device and either its control service 00250 * or picture service, then respond with the variable value. 00251 * 00252 * Parameters: 00253 * cgv_event -- The control get variable request event structure 00254 * 00255 *****************************************************************************/ 00256 int TvDeviceHandleGetVarRequest(UpnpStateVarRequest *); 00257 00258 /****************************************************************************** 00259 * TvDeviceHandleActionRequest 00260 * 00261 * Description: 00262 * Called during an action request callback. If the 00263 * request is for this device and either its control service 00264 * or picture service, then perform the action and respond. 00265 * 00266 * Parameters: 00267 * ca_event -- The control action request event structure 00268 * 00269 *****************************************************************************/ 00270 int TvDeviceHandleActionRequest(UpnpActionRequest *); 00271 00272 /****************************************************************************** 00273 * TvDeviceCallbackEventHandler 00274 * 00275 * Description: 00276 * The callback handler registered with the SDK while registering 00277 * root device. Dispatches the request to the appropriate procedure 00278 * based on the value of EventType. The four requests handled by the 00279 * device are: 00280 * 1) Event Subscription requests. 00281 * 2) Get Variable requests. 00282 * 3) Action requests. 00283 * 00284 * Parameters: 00285 * 00286 * EventType -- The type of callback event 00287 * Event -- Data structure containing event data 00288 * Cookie -- Optional data specified during callback registration 00289 * 00290 *****************************************************************************/ 00291 int TvDeviceCallbackEventHandler(Upnp_EventType, void*, void*); 00292 00293 /****************************************************************************** 00294 * TvDeviceSetServiceTableVar 00295 * 00296 * Description: 00297 * Update the TvDevice service state table, and notify all subscribed 00298 * control points of the updated state. Note that since this function 00299 * blocks on the mutex TVDevMutex, to avoid a hang this function should 00300 * not be called within any other function that currently has this mutex 00301 * locked. 00302 * 00303 * Parameters: 00304 * service -- The service number (TV_SERVICE_CONTROL or TV_SERVICE_PICTURE) 00305 * variable -- The variable number (TV_CONTROL_POWER, TV_CONTROL_CHANNEL, 00306 * TV_CONTROL_VOLUME, TV_PICTURE_COLOR, TV_PICTURE_TINT, 00307 * TV_PICTURE_CONTRAST, or TV_PICTURE_BRIGHTNESS) 00308 * value -- The string representation of the new value 00309 * 00310 *****************************************************************************/ 00311 int TvDeviceSetServiceTableVar(unsigned int, unsigned int, char*); 00312 00313 //Control Service Actions 00314 00315 /****************************************************************************** 00316 * TvDevicePowerOn 00317 * 00318 * Description: 00319 * Turn the power on. 00320 * 00321 * Parameters: 00322 * 00323 * IXML_Document * in - document of action request 00324 * IXML_Document **out - action result 00325 * char **errorString - errorString (in case action was unsuccessful) 00326 * 00327 *****************************************************************************/ 00328 int TvDevicePowerOn(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString); 00329 00330 /****************************************************************************** 00331 * TvDevicePowerOff 00332 * 00333 * Description: 00334 * Turn the power off. 00335 * 00336 * Parameters: 00337 * 00338 * IXML_Document * in - document of action request 00339 * IXML_Document **out - action result 00340 * char **errorString - errorString (in case action was unsuccessful) 00341 * 00342 *****************************************************************************/ 00343 int TvDevicePowerOff(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00344 00345 /****************************************************************************** 00346 * TvDeviceSetChannel 00347 * 00348 * Description: 00349 * Change the channel, update the TvDevice control service 00350 * state table, and notify all subscribed control points of the 00351 * updated state. 00352 * 00353 * Parameters: 00354 * 00355 * IXML_Document * in - action request document 00356 * IXML_Document **out - action result document 00357 * char **errorString - errorString (in case action was unsuccessful) 00358 * 00359 *****************************************************************************/ 00360 int TvDeviceSetChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00361 00362 /****************************************************************************** 00363 * TvDeviceIncreaseChannel 00364 * 00365 * Description: 00366 * Increase the channel. 00367 * 00368 * Parameters: 00369 * 00370 * IXML_Document * in - action request document 00371 * IXML_Document **out - action result document 00372 * char **errorString - errorString (in case action was unsuccessful) 00373 * 00374 *****************************************************************************/ 00375 int TvDeviceIncreaseChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00376 /****************************************************************************** 00377 * TvDeviceDecreaseChannel 00378 * 00379 * Description: 00380 * Decrease the channel. 00381 * 00382 * Parameters: 00383 * 00384 * IXML_Document * in - action request document 00385 * IXML_Document **out - action result document 00386 * char **errorString - errorString (in case action was unsuccessful) 00387 * 00388 *****************************************************************************/ 00389 int TvDeviceDecreaseChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00390 /****************************************************************************** 00391 * TvDeviceSetVolume 00392 * 00393 * Description: 00394 * Change the volume, update the TvDevice control service 00395 * state table, and notify all subscribed control points of the 00396 * updated state. 00397 * 00398 * Parameters: 00399 * 00400 * IXML_Document * in - action request document 00401 * IXML_Document **out - action result document 00402 * char **errorString - errorString (in case action was unsuccessful) 00403 * 00404 *****************************************************************************/ 00405 int TvDeviceSetVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00406 00407 /****************************************************************************** 00408 * TvDeviceIncreaseVolume 00409 * 00410 * Description: 00411 * Increase the volume. 00412 * 00413 * Parameters: 00414 * 00415 * 00416 * IXML_Document * in - action request document 00417 * IXML_Document **out - action result document 00418 * char **errorString - errorString (in case action was unsuccessful) 00419 *****************************************************************************/ 00420 int TvDeviceIncreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00421 00422 00423 /****************************************************************************** 00424 * TvDeviceDecreaseVolume 00425 * 00426 * Description: 00427 * Decrease the volume. 00428 * 00429 * Parameters: 00430 * 00431 * IXML_Document * in - action request document 00432 * IXML_Document **out - action result document 00433 * char **errorString - errorString (in case action was unsuccessful) 00434 * 00435 *****************************************************************************/ 00436 int TvDeviceDecreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00437 00438 00439 //Picture Service Actions 00440 00441 /****************************************************************************** 00442 * TvDeviceSetColor 00443 * 00444 * Description: 00445 * Change the color, update the TvDevice picture service 00446 * state table, and notify all subscribed control points of the 00447 * updated state. 00448 * 00449 * Parameters: 00450 * 00451 * IXML_Document * in - action request document 00452 * IXML_Document **out - action result document 00453 * char **errorString - errorString (in case action was unsuccessful) 00454 * 00455 *****************************************************************************/ 00456 int TvDeviceSetColor(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00457 00458 00459 /****************************************************************************** 00460 * TvDeviceIncreaseColor 00461 * 00462 * Description: 00463 * Increase the color. 00464 * 00465 * Parameters: 00466 * 00467 * IXML_Document * in - action request document 00468 * IXML_Document **out - action result document 00469 * char **errorString - errorString (in case action was unsuccessful) 00470 *****************************************************************************/ 00471 int TvDeviceIncreaseColor(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString); 00472 00473 /****************************************************************************** 00474 * TvDeviceDecreaseColor 00475 * 00476 * Description: 00477 * Decrease the color. 00478 * 00479 * Parameters: 00480 * 00481 * IXML_Document * in - action request document 00482 * IXML_Document **out - action result document 00483 * char **errorString - errorString (in case action was unsuccessful) 00484 *****************************************************************************/ 00485 int TvDeviceDecreaseColor(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString); 00486 00487 /****************************************************************************** 00488 * TvDeviceSetTint 00489 * 00490 * Description: 00491 * Change the tint, update the TvDevice picture service 00492 * state table, and notify all subscribed control points of the 00493 * updated state. 00494 * 00495 * Parameters: 00496 * 00497 * IXML_Document * in - action request document 00498 * IXML_Document **out - action result document 00499 * char **errorString - errorString (in case action was unsuccessful) 00500 * 00501 *****************************************************************************/ 00502 int TvDeviceSetTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00503 00504 /****************************************************************************** 00505 * TvDeviceIncreaseTint 00506 * 00507 * Description: 00508 * Increase tint. 00509 * 00510 * Parameters: 00511 * 00512 * IXML_Document * in - action request document 00513 * IXML_Document **out - action result document 00514 * char **errorString - errorString (in case action was unsuccessful) 00515 * 00516 *****************************************************************************/ 00517 int TvDeviceIncreaseTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00518 00519 /****************************************************************************** 00520 * TvDeviceDecreaseTint 00521 * 00522 * Description: 00523 * Decrease tint. 00524 * 00525 * Parameters: 00526 * 00527 * IXML_Document * in - action request document 00528 * IXML_Document **out - action result document 00529 * char **errorString - errorString (in case action was unsuccessful) 00530 * 00531 *****************************************************************************/ 00532 int TvDeviceDecreaseTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00533 00534 /***************************************************************************** 00535 * TvDeviceSetContrast 00536 * 00537 * Description: 00538 * Change the contrast, update the TvDevice picture service 00539 * state table, and notify all subscribed control points of the 00540 * updated state. 00541 * 00542 * Parameters: 00543 * 00544 * IXML_Document * in - action request document 00545 * IXML_Document **out - action result document 00546 * char **errorString - errorString (in case action was unsuccessful) 00547 * 00548 ****************************************************************************/ 00549 int TvDeviceSetContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00550 00551 /****************************************************************************** 00552 * TvDeviceIncreaseContrast 00553 * 00554 * Description: 00555 * 00556 * Increase the contrast. 00557 * 00558 * Parameters: 00559 * 00560 * IXML_Document * in - action request document 00561 * IXML_Document **out - action result document 00562 * char **errorString - errorString (in case action was unsuccessful) 00563 * 00564 *****************************************************************************/ 00565 int TvDeviceIncreaseContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00566 /****************************************************************************** 00567 * TvDeviceDecreaseContrast 00568 * 00569 * Description: 00570 * Decrease the contrast. 00571 * 00572 * Parameters: 00573 * 00574 * IXML_Document * in - action request document 00575 * IXML_Document **out - action result document 00576 * char **errorString - errorString (in case action was unsuccessful) 00577 * 00578 *****************************************************************************/ 00579 int TvDeviceDecreaseContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00580 00581 /****************************************************************************** 00582 * TvDeviceSetBrightness 00583 * 00584 * Description: 00585 * Change the brightness, update the TvDevice picture service 00586 * state table, and notify all subscribed control points of the 00587 * updated state. 00588 * 00589 * Parameters: 00590 * brightness -- The brightness value to change to. 00591 * 00592 *****************************************************************************/ 00593 int TvDeviceSetBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00594 00595 /****************************************************************************** 00596 * TvDeviceIncreaseBrightness 00597 * 00598 * Description: 00599 * Increase brightness. 00600 * 00601 * Parameters: 00602 * 00603 * IXML_Document * in - action request document 00604 * IXML_Document **out - action result document 00605 * char **errorString - errorString (in case action was unsuccessful) 00606 * 00607 *****************************************************************************/ 00608 int TvDeviceIncreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00609 00610 /****************************************************************************** 00611 * TvDeviceDecreaseBrightness 00612 * 00613 * Description: 00614 * Decrease brightnesss. 00615 * 00616 * Parameters: 00617 * IXML_Document * in - action request document 00618 * IXML_Document **out - action result document 00619 * char **errorString - errorString (in case action was unsuccessful) 00620 * 00621 *****************************************************************************/ 00622 int TvDeviceDecreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString); 00623 00624 int TvDeviceStart(char * ip_address, unsigned short port,char * desc_doc_name, 00625 char *web_dir_path, print_string pfun); 00626 int TvDeviceStop(); 00627 00628 #ifdef __cplusplus 00629 } 00630 #endif 00631 00632 #endif