merged: Platinum from linuxport branches
[xbmc:xbmc-antiquated.git] / xbmc / lib / libUPnP / Platinum / Source / Tests / MediaRenderer / MediaRendererTest.cpp
1 /*****************************************************************\r
2 |\r
3 |   Platinum - Test UPnP A/V MediaRenderer\r
4 |\r
5 |   Copyright (c) 2004-2008 Sylvain Rebaud\r
6 |   Author: Sylvain Rebaud (sylvain@rebaud.com)\r
7 |\r
8  ****************************************************************/\r
9 \r
10 /*----------------------------------------------------------------------\r
11 |   includes\r
12 +---------------------------------------------------------------------*/\r
13 #include "PltUPnP.h"\r
14 #include "PltMediaRenderer.h"\r
15 \r
16 #include <stdlib.h>\r
17 \r
18 /*----------------------------------------------------------------------\r
19 |   globals\r
20 +---------------------------------------------------------------------*/\r
21 struct Options {\r
22     const char* friendly_name;\r
23 } Options;\r
24 \r
25 /*----------------------------------------------------------------------\r
26 |   PrintUsageAndExit\r
27 +---------------------------------------------------------------------*/\r
28 static void\r
29 PrintUsageAndExit(char** args)\r
30 {\r
31     fprintf(stderr, "usage: %s [-f <friendly_name>]\n", args[0]);\r
32     fprintf(stderr, "-f : optional upnp server friendly name\n");\r
33     fprintf(stderr, "<path> : local path to serve\n");\r
34     exit(1);\r
35 }\r
36 \r
37 /*----------------------------------------------------------------------\r
38 |   ParseCommandLine\r
39 +---------------------------------------------------------------------*/\r
40 static void\r
41 ParseCommandLine(char** args)\r
42 {\r
43     const char* arg;\r
44     char**      tmp = args+1;\r
45 \r
46     /* default values */\r
47     Options.friendly_name = NULL;\r
48 \r
49     while ((arg = *tmp++)) {\r
50         if (!strcmp(arg, "-f")) {\r
51             Options.friendly_name = *tmp++;\r
52         } else {\r
53             fprintf(stderr, "ERROR: too many arguments\n");\r
54             PrintUsageAndExit(args);\r
55         }\r
56     }\r
57 }\r
58 \r
59 /*----------------------------------------------------------------------\r
60 |   main\r
61 +---------------------------------------------------------------------*/\r
62 int\r
63 main(int /* argc */, char** argv)\r
64 {   \r
65     PLT_UPnP upnp;\r
66 \r
67     /* parse command line */\r
68     ParseCommandLine(argv);\r
69 \r
70     PLT_DeviceHostReference device(\r
71         new PLT_MediaRenderer(\r
72             NULL,\r
73             Options.friendly_name?Options.friendly_name:"Platinum Media Renderer"));\r
74     upnp.AddDevice(device);\r
75     bool added = true;\r
76 \r
77     upnp.Start();\r
78 \r
79     char buf[256];\r
80     while (gets(buf)) {\r
81         if (*buf == 'q')\r
82             break;\r
83 \r
84         if (*buf == 's') {\r
85             if (added) {\r
86                 upnp.RemoveDevice(device);\r
87             } else {\r
88                 upnp.AddDevice(device);\r
89             }\r
90             added = !added;\r
91         }\r
92     }\r
93 \r
94     upnp.Stop();\r
95     return 0;\r
96 }\r