libUPnP  1.8.0
upnp_tv_device.h
1 /**************************************************************************
2  *
3  * Copyright (c) 2000-2003 Intel Corporation
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * - Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * - Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * - Neither name of Intel Corporation nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  **************************************************************************/
31 
32 
33 #ifndef UPNP_TV_DEVICE_H
34 #define UPNP_TV_DEVICE_H
35 
36 
37 #include <stdio.h>
38 #include <signal.h>
39 
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 
46 #include "sample_util.h"
47 
48 
49 #include "ithread.h"
50 #include "upnp.h"
51 
52 
53 #include <stdlib.h>
54 #include <string.h>
55 
56 
57 #ifdef WIN32
58  /* Do not #include <unistd.h> */
59 #else
60  #include <unistd.h>
61 #endif
62 
63 
64 //Color constants
65 #define MAX_COLOR 10
66 #define MIN_COLOR 1
67 
68 //Brightness constants
69 #define MAX_BRIGHTNESS 10
70 #define MIN_BRIGHTNESS 1
71 
72 //Power constants
73 #define POWER_ON 1
74 #define POWER_OFF 0
75 
76 //Tint constants
77 #define MAX_TINT 10
78 #define MIN_TINT 1
79 
80 //Volume constants
81 #define MAX_VOLUME 10
82 #define MIN_VOLUME 1
83 
84 //Contrast constants
85 #define MAX_CONTRAST 10
86 #define MIN_CONTRAST 1
87 
88 //Channel constants
89 #define MAX_CHANNEL 100
90 #define MIN_CHANNEL 1
91 
92 //Number of services.
93 #define TV_SERVICE_SERVCOUNT 2
94 
95 //Index of control service
96 #define TV_SERVICE_CONTROL 0
97 
98 //Index of picture service
99 #define TV_SERVICE_PICTURE 1
100 
101 //Number of control variables
102 #define TV_CONTROL_VARCOUNT 3
103 
104 //Index of power variable
105 #define TV_CONTROL_POWER 0
106 
107 //Index of channel variable
108 #define TV_CONTROL_CHANNEL 1
109 
110 //Index of volume variable
111 #define TV_CONTROL_VOLUME 2
112 
113 //Number of picture variables
114 #define TV_PICTURE_VARCOUNT 4
115 
116 //Index of color variable
117 #define TV_PICTURE_COLOR 0
118 
119 //Index of tint variable
120 #define TV_PICTURE_TINT 1
121 
122 //Index of contrast variable
123 #define TV_PICTURE_CONTRAST 2
124 
125 //Index of brightness variable
126 #define TV_PICTURE_BRIGHTNESS 3
127 
128 //Max value length
129 #define TV_MAX_VAL_LEN 5
130 
131 //Max actions
132 #define TV_MAXACTIONS 12
133 
134 /* This should be the maximum VARCOUNT from above */
135 #define TV_MAXVARS TV_PICTURE_VARCOUNT
136 
137 
138 extern char TvDeviceType[];
139 
140 extern char *TvServiceType[];
141 
142 
143 
144 /******************************************************************************
145  * upnp_action
146  *
147  * Description:
148  * Prototype for all actions. For each action that a service
149  * implements, there is a corresponding function with this prototype.
150  * Pointers to these functions, along with action names, are stored
151  * in the service table. When an action request comes in the action
152  * name is matched, and the appropriate function is called.
153  * Each function returns UPNP_E_SUCCESS, on success, and a nonzero
154  * error code on failure.
155  *
156  * Parameters:
157  *
158  * IXML_Document * request - document of action request
159  * IXML_Document **out - action result
160  * char **errorString - errorString (in case action was unsuccessful)
161  *
162  *****************************************************************************/
163 
164 typedef int (*upnp_action) (IXML_Document *request, IXML_Document **out, char **errorString);
165 
166 /* Structure for storing Tv Service
167  identifiers and state table */
168 struct TvService {
169 
170  char UDN[NAME_SIZE]; /* Universally Unique Device Name */
171  char ServiceId[NAME_SIZE];
172  char ServiceType[NAME_SIZE];
173  char *VariableName[TV_MAXVARS];
174  char *VariableStrVal[TV_MAXVARS];
175  char *ActionNames[TV_MAXACTIONS];
176  upnp_action actions[TV_MAXACTIONS];
177  unsigned int VariableCount;
178 };
179 
180 //Array of service structures
181 extern struct TvService tv_service_table[];
182 
183 //Device handle returned from sdk
184 extern UpnpDevice_Handle device_handle;
185 
186 
187 /* Mutex for protecting the global state table data
188  in a multi-threaded, asynchronous environment.
189  All functions should lock this mutex before reading
190  or writing the state table data. */
191 extern ithread_mutex_t TVDevMutex;
192 
193 
194 
195 /******************************************************************************
196  * SetActionTable
197  *
198  * Description:
199  * Initializes the action table for the specified service.
200  * Note that
201  * knowledge of the service description is
202  * assumed. Action names are hardcoded.
203  * Parameters:
204  * int serviceType - one of TV_SERVICE_CONTROL or, TV_SERVICE_PICTURE
205  * struct TvService *out - service containing action table to set.
206  *
207  *****************************************************************************/
208 int SetActionTable(int serviceType, struct TvService *out);
209 
210 /******************************************************************************
211  * TvDeviceStateTableInit
212  *
213  * Description:
214  * Initialize the device state table for
215  * this TvDevice, pulling identifier info
216  * from the description Document. Note that
217  * knowledge of the service description is
218  * assumed. State table variables and default
219  * values are currently hardcoded in this file
220  * rather than being read from service description
221  * documents.
222  *
223  * Parameters:
224  * DescDocURL -- The description document URL
225  *
226  *****************************************************************************/
227 int TvDeviceStateTableInit(char*);
228 
229 
230 /******************************************************************************
231  * TvDeviceHandleSubscriptionRequest
232  *
233  * Description:
234  * Called during a subscription request callback. If the
235  * subscription request is for this device and either its
236  * control service or picture service, then accept it.
237  *
238  * Parameters:
239  * sr_event -- The subscription request event structure
240  *
241  *****************************************************************************/
242 int TvDeviceHandleSubscriptionRequest(const UpnpSubscriptionRequest *);
243 
244 /******************************************************************************
245  * TvDeviceHandleGetVarRequest
246  *
247  * Description:
248  * Called during a get variable request callback. If the
249  * request is for this device and either its control service
250  * or picture service, then respond with the variable value.
251  *
252  * Parameters:
253  * cgv_event -- The control get variable request event structure
254  *
255  *****************************************************************************/
256 int TvDeviceHandleGetVarRequest(UpnpStateVarRequest *);
257 
258 /******************************************************************************
259  * TvDeviceHandleActionRequest
260  *
261  * Description:
262  * Called during an action request callback. If the
263  * request is for this device and either its control service
264  * or picture service, then perform the action and respond.
265  *
266  * Parameters:
267  * ca_event -- The control action request event structure
268  *
269  *****************************************************************************/
270 int TvDeviceHandleActionRequest(UpnpActionRequest *);
271 
272 /******************************************************************************
273  * TvDeviceCallbackEventHandler
274  *
275  * Description:
276  * The callback handler registered with the SDK while registering
277  * root device. Dispatches the request to the appropriate procedure
278  * based on the value of EventType. The four requests handled by the
279  * device are:
280  * 1) Event Subscription requests.
281  * 2) Get Variable requests.
282  * 3) Action requests.
283  *
284  * Parameters:
285  *
286  * EventType -- The type of callback event
287  * Event -- Data structure containing event data
288  * Cookie -- Optional data specified during callback registration
289  *
290  *****************************************************************************/
291 int TvDeviceCallbackEventHandler(Upnp_EventType, void*, void*);
292 
293 /******************************************************************************
294  * TvDeviceSetServiceTableVar
295  *
296  * Description:
297  * Update the TvDevice service state table, and notify all subscribed
298  * control points of the updated state. Note that since this function
299  * blocks on the mutex TVDevMutex, to avoid a hang this function should
300  * not be called within any other function that currently has this mutex
301  * locked.
302  *
303  * Parameters:
304  * service -- The service number (TV_SERVICE_CONTROL or TV_SERVICE_PICTURE)
305  * variable -- The variable number (TV_CONTROL_POWER, TV_CONTROL_CHANNEL,
306  * TV_CONTROL_VOLUME, TV_PICTURE_COLOR, TV_PICTURE_TINT,
307  * TV_PICTURE_CONTRAST, or TV_PICTURE_BRIGHTNESS)
308  * value -- The string representation of the new value
309  *
310  *****************************************************************************/
311 int TvDeviceSetServiceTableVar(unsigned int, unsigned int, char*);
312 
313 //Control Service Actions
314 
315 /******************************************************************************
316  * TvDevicePowerOn
317  *
318  * Description:
319  * Turn the power on.
320  *
321  * Parameters:
322  *
323  * IXML_Document * in - document of action request
324  * IXML_Document **out - action result
325  * char **errorString - errorString (in case action was unsuccessful)
326  *
327  *****************************************************************************/
328 int TvDevicePowerOn(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString);
329 
330 /******************************************************************************
331  * TvDevicePowerOff
332  *
333  * Description:
334  * Turn the power off.
335  *
336  * Parameters:
337  *
338  * IXML_Document * in - document of action request
339  * IXML_Document **out - action result
340  * char **errorString - errorString (in case action was unsuccessful)
341  *
342  *****************************************************************************/
343 int TvDevicePowerOff(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
344 
345 /******************************************************************************
346  * TvDeviceSetChannel
347  *
348  * Description:
349  * Change the channel, update the TvDevice control service
350  * state table, and notify all subscribed control points of the
351  * updated state.
352  *
353  * Parameters:
354  *
355  * IXML_Document * in - action request document
356  * IXML_Document **out - action result document
357  * char **errorString - errorString (in case action was unsuccessful)
358  *
359  *****************************************************************************/
360 int TvDeviceSetChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
361 
362 /******************************************************************************
363  * TvDeviceIncreaseChannel
364  *
365  * Description:
366  * Increase the channel.
367  *
368  * Parameters:
369  *
370  * IXML_Document * in - action request document
371  * IXML_Document **out - action result document
372  * char **errorString - errorString (in case action was unsuccessful)
373  *
374  *****************************************************************************/
375 int TvDeviceIncreaseChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
376 /******************************************************************************
377  * TvDeviceDecreaseChannel
378  *
379  * Description:
380  * Decrease the channel.
381  *
382  * Parameters:
383  *
384  * IXML_Document * in - action request document
385  * IXML_Document **out - action result document
386  * char **errorString - errorString (in case action was unsuccessful)
387  *
388  *****************************************************************************/
389 int TvDeviceDecreaseChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
390 /******************************************************************************
391  * TvDeviceSetVolume
392  *
393  * Description:
394  * Change the volume, update the TvDevice control service
395  * state table, and notify all subscribed control points of the
396  * updated state.
397  *
398  * Parameters:
399  *
400  * IXML_Document * in - action request document
401  * IXML_Document **out - action result document
402  * char **errorString - errorString (in case action was unsuccessful)
403  *
404  *****************************************************************************/
405 int TvDeviceSetVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
406 
407 /******************************************************************************
408  * TvDeviceIncreaseVolume
409  *
410  * Description:
411  * Increase the volume.
412  *
413  * Parameters:
414  *
415  *
416  * IXML_Document * in - action request document
417  * IXML_Document **out - action result document
418  * char **errorString - errorString (in case action was unsuccessful)
419  *****************************************************************************/
420 int TvDeviceIncreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
421 
422 
423 /******************************************************************************
424  * TvDeviceDecreaseVolume
425  *
426  * Description:
427  * Decrease the volume.
428  *
429  * Parameters:
430  *
431  * IXML_Document * in - action request document
432  * IXML_Document **out - action result document
433  * char **errorString - errorString (in case action was unsuccessful)
434  *
435  *****************************************************************************/
436 int TvDeviceDecreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
437 
438 
439 //Picture Service Actions
440 
441 /******************************************************************************
442  * TvDeviceSetColor
443  *
444  * Description:
445  * Change the color, update the TvDevice picture service
446  * state table, and notify all subscribed control points of the
447  * updated state.
448  *
449  * Parameters:
450  *
451  * IXML_Document * in - action request document
452  * IXML_Document **out - action result document
453  * char **errorString - errorString (in case action was unsuccessful)
454  *
455  *****************************************************************************/
456 int TvDeviceSetColor(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
457 
458 
459 /******************************************************************************
460  * TvDeviceIncreaseColor
461  *
462  * Description:
463  * Increase the color.
464  *
465  * Parameters:
466  *
467  * IXML_Document * in - action request document
468  * IXML_Document **out - action result document
469  * char **errorString - errorString (in case action was unsuccessful)
470  *****************************************************************************/
471 int TvDeviceIncreaseColor(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString);
472 
473 /******************************************************************************
474  * TvDeviceDecreaseColor
475  *
476  * Description:
477  * Decrease the color.
478  *
479  * Parameters:
480  *
481  * IXML_Document * in - action request document
482  * IXML_Document **out - action result document
483  * char **errorString - errorString (in case action was unsuccessful)
484  *****************************************************************************/
485 int TvDeviceDecreaseColor(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString);
486 
487 /******************************************************************************
488  * TvDeviceSetTint
489  *
490  * Description:
491  * Change the tint, update the TvDevice picture service
492  * state table, and notify all subscribed control points of the
493  * updated state.
494  *
495  * Parameters:
496  *
497  * IXML_Document * in - action request document
498  * IXML_Document **out - action result document
499  * char **errorString - errorString (in case action was unsuccessful)
500  *
501  *****************************************************************************/
502 int TvDeviceSetTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
503 
504 /******************************************************************************
505  * TvDeviceIncreaseTint
506  *
507  * Description:
508  * Increase tint.
509  *
510  * Parameters:
511  *
512  * IXML_Document * in - action request document
513  * IXML_Document **out - action result document
514  * char **errorString - errorString (in case action was unsuccessful)
515  *
516  *****************************************************************************/
517 int TvDeviceIncreaseTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
518 
519 /******************************************************************************
520  * TvDeviceDecreaseTint
521  *
522  * Description:
523  * Decrease tint.
524  *
525  * Parameters:
526  *
527  * IXML_Document * in - action request document
528  * IXML_Document **out - action result document
529  * char **errorString - errorString (in case action was unsuccessful)
530  *
531  *****************************************************************************/
532 int TvDeviceDecreaseTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
533 
534 /*****************************************************************************
535  * TvDeviceSetContrast
536  *
537  * Description:
538  * Change the contrast, update the TvDevice picture service
539  * state table, and notify all subscribed control points of the
540  * updated state.
541  *
542  * Parameters:
543  *
544  * IXML_Document * in - action request document
545  * IXML_Document **out - action result document
546  * char **errorString - errorString (in case action was unsuccessful)
547  *
548  ****************************************************************************/
549 int TvDeviceSetContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
550 
551 /******************************************************************************
552  * TvDeviceIncreaseContrast
553  *
554  * Description:
555  *
556  * Increase the contrast.
557  *
558  * Parameters:
559  *
560  * IXML_Document * in - action request document
561  * IXML_Document **out - action result document
562  * char **errorString - errorString (in case action was unsuccessful)
563  *
564  *****************************************************************************/
565 int TvDeviceIncreaseContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
566 /******************************************************************************
567  * TvDeviceDecreaseContrast
568  *
569  * Description:
570  * Decrease the contrast.
571  *
572  * Parameters:
573  *
574  * IXML_Document * in - action request document
575  * IXML_Document **out - action result document
576  * char **errorString - errorString (in case action was unsuccessful)
577  *
578  *****************************************************************************/
579 int TvDeviceDecreaseContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
580 
581 /******************************************************************************
582  * TvDeviceSetBrightness
583  *
584  * Description:
585  * Change the brightness, update the TvDevice picture service
586  * state table, and notify all subscribed control points of the
587  * updated state.
588  *
589  * Parameters:
590  * brightness -- The brightness value to change to.
591  *
592  *****************************************************************************/
593 int TvDeviceSetBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
594 
595 /******************************************************************************
596  * TvDeviceIncreaseBrightness
597  *
598  * Description:
599  * Increase brightness.
600  *
601  * Parameters:
602  *
603  * IXML_Document * in - action request document
604  * IXML_Document **out - action result document
605  * char **errorString - errorString (in case action was unsuccessful)
606  *
607  *****************************************************************************/
608 int TvDeviceIncreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
609 
610 /******************************************************************************
611  * TvDeviceDecreaseBrightness
612  *
613  * Description:
614  * Decrease brightnesss.
615  *
616  * Parameters:
617  * IXML_Document * in - action request document
618  * IXML_Document **out - action result document
619  * char **errorString - errorString (in case action was unsuccessful)
620  *
621  *****************************************************************************/
622 int TvDeviceDecreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
623 
624 int TvDeviceStart(char * ip_address, unsigned short port,char * desc_doc_name,
625  char *web_dir_path, print_string pfun);
626 int TvDeviceStop();
627 
628 #ifdef __cplusplus
629 }
630 #endif
631 
632 #endif
struct s_UpnpSubscriptionRequest UpnpSubscriptionRequest
Definition: SubscriptionRequest.h:17
struct s_UpnpStateVarRequest UpnpStateVarRequest
Definition: StateVarRequest.h:18
int UpnpDevice_Handle
Returned when a device application registers with UpnpRegisterRootDevice or UpnpRegisterRootDevice2.
Definition: upnp.h:470
Definition: upnp_tv_device.h:168
Data structure representing the DOM Document.
Definition: ixml.h:183
struct s_UpnpActionRequest UpnpActionRequest
Definition: ActionRequest.h:17