merged: Platinum from linuxport branches
[xbmc:xbmc-antiquated.git] / xbmc / lib / libUPnP / Platinum / Source / Tests / LightSample / PltLightSample.cpp
1 /*****************************************************************\r
2 |\r
3 |   Platinum - Light Sample Device\r
4 |\r
5 |   (c) 2004 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 "NptTypes.h"\r
14 #include "Platinum.h"\r
15 #include "PltLightSample.h"\r
16 \r
17 /*----------------------------------------------------------------------\r
18 |   forward references\r
19 +---------------------------------------------------------------------*/\r
20 extern NPT_UInt8 SCPDXML[];\r
21 \r
22 /*----------------------------------------------------------------------\r
23 |   PLT_LightSampleDevice::PLT_LightSampleDevice\r
24 +---------------------------------------------------------------------*/\r
25 PLT_LightSampleDevice::PLT_LightSampleDevice(const char* FriendlyName, const char* UUID) :      \r
26     PLT_DeviceHost("/", UUID, "urn:schemas-upnp-org:device:SwitchPower:1", FriendlyName)\r
27 {\r
28     PLT_Service* service = new PLT_Service(\r
29         this,\r
30         "urn:schemas-upnp-org:service:SwitchPower:1", \r
31         "urn:upnp-org:serviceId:SwitchPower.001");\r
32 \r
33     if (NPT_SUCCEEDED(service->SetSCPDXML((const char*)SCPDXML))) {\r
34         service->InitURLs("SwitchPower", m_UUID);\r
35         AddService(service);\r
36     } else {\r
37         delete service;\r
38     }\r
39 \r
40     service->SetStateVariable("Status", "True");\r
41 }\r
42 \r
43 /*----------------------------------------------------------------------\r
44 |   PLT_LightSampleDevice::~PLT_LightSampleDevice\r
45 +---------------------------------------------------------------------*/\r
46 PLT_LightSampleDevice::~PLT_LightSampleDevice()\r
47 {\r
48 }\r
49 \r
50 /*----------------------------------------------------------------------\r
51 |   PLT_LightSampleDevice::OnAction\r
52 +---------------------------------------------------------------------*/\r
53 NPT_Result\r
54 PLT_LightSampleDevice::OnAction(PLT_ActionReference&          action,\r
55                                 const NPT_HttpRequestContext& context)\r
56 {\r
57     NPT_COMPILER_UNUSED(context);\r
58 \r
59     /* parse the action name */\r
60     NPT_String name = action->GetActionDesc()->GetName();\r
61     if (name.Compare("SetTarget") == 0) {\r
62         NPT_String value;\r
63         action->GetArgumentValue("newTargetValue", value);\r
64 \r
65         PLT_StateVariable* variable = action->GetActionDesc()->GetService()->FindStateVariable("Status");\r
66         if (NPT_FAILED(variable->SetValue(value))) {\r
67             action->SetError(402, "Invalid Args");\r
68             return NPT_FAILURE;\r
69         }\r
70         return NPT_SUCCESS;\r
71     } else if (name.Compare("GetStatus") == 0) {\r
72         PLT_StateVariable* variable = action->GetActionDesc()->GetService()->FindStateVariable("Status");\r
73         if (variable) {\r
74             action->SetArgumentValue("ResultStatus", variable->GetValue());\r
75             return NPT_SUCCESS;\r
76         }\r
77     }\r
78     \r
79     action->SetError(501, "Action Failed");\r
80     return NPT_FAILURE;\r
81 }\r
82 \r
83 NPT_UInt8 SCPDXML[957] =\r
84 {\r
85   0x20, 0x20, 0x3C, 0x3F, 0x78, 0x6D, 0x6C, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3D, 0x22, 0x31, 0x2E, 0x30, \r
86   0x22, 0x20, 0x65, 0x6E, 0x63, 0x6F, 0x64, 0x69, 0x6E, 0x67, 0x3D, 0x22, 0x75, 0x74, 0x66, 0x2D, 0x38, 0x22, 0x20, 0x3F, \r
87   0x3E, 0x20, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x73, 0x63, 0x70, 0x64, 0x20, 0x78, 0x6D, 0x6C, 0x6E, 0x73, 0x3D, 0x22, 0x75, \r
88   0x72, 0x6E, 0x3A, 0x73, 0x63, 0x68, 0x65, 0x6D, 0x61, 0x73, 0x2D, 0x75, 0x70, 0x6E, 0x70, 0x2D, 0x6F, 0x72, 0x67, 0x3A, \r
89   0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2D, 0x31, 0x2D, 0x30, 0x22, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x73, 0x70, \r
90   0x65, 0x63, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x6D, 0x61, 0x6A, 0x6F, 0x72, \r
91   0x3E, 0x31, 0x3C, 0x2F, 0x6D, 0x61, 0x6A, 0x6F, 0x72, 0x3E, 0x20, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x6D, 0x69, 0x6E, 0x6F, \r
92   0x72, 0x3E, 0x30, 0x3C, 0x2F, 0x6D, 0x69, 0x6E, 0x6F, 0x72, 0x3E, 0x20, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x2F, 0x73, 0x70, \r
93   0x65, 0x63, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x61, 0x63, 0x74, 0x69, 0x6F, \r
94   0x6E, 0x4C, 0x69, 0x73, 0x74, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x61, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x3E, 0x0D, 0x0A, \r
95   0x20, 0x20, 0x3C, 0x6E, 0x61, 0x6D, 0x65, 0x3E, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x3C, 0x2F, 0x6E, \r
96   0x61, 0x6D, 0x65, 0x3E, 0x20, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x61, 0x72, 0x67, 0x75, 0x6D, 0x65, 0x6E, 0x74, 0x4C, 0x69, \r
97   0x73, 0x74, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x61, 0x72, 0x67, 0x75, 0x6D, 0x65, 0x6E, 0x74, 0x3E, 0x0D, 0x0A, 0x20, \r
98   0x20, 0x3C, 0x6E, 0x61, 0x6D, 0x65, 0x3E, 0x52, 0x65, 0x73, 0x75, 0x6C, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x3C, \r
99   0x2F, 0x6E, 0x61, 0x6D, 0x65, 0x3E, 0x20, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6F, \r
100   0x6E, 0x3E, 0x6F, 0x75, 0x74, 0x3C, 0x2F, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x3E, 0x20, 0x0D, 0x0A, \r
101   0x20, 0x20, 0x3C, 0x72, 0x65, 0x6C, 0x61, 0x74, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x56, 0x61, 0x72, 0x69, 0x61, \r
102   0x62, 0x6C, 0x65, 0x3E, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x3C, 0x2F, 0x72, 0x65, 0x6C, 0x61, 0x74, 0x65, 0x64, 0x53, \r
103   0x74, 0x61, 0x74, 0x65, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6C, 0x65, 0x3E, 0x20, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x2F, \r
104   0x61, 0x72, 0x67, 0x75, 0x6D, 0x65, 0x6E, 0x74, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x2F, 0x61, 0x72, 0x67, 0x75, 0x6D, \r
105   0x65, 0x6E, 0x74, 0x4C, 0x69, 0x73, 0x74, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x2F, 0x61, 0x63, 0x74, 0x69, 0x6F, 0x6E, \r
106   0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x61, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x6E, 0x61, \r
107   0x6D, 0x65, 0x3E, 0x53, 0x65, 0x74, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x3C, 0x2F, 0x6E, 0x61, 0x6D, 0x65, 0x3E, 0x20, \r
108   0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x61, 0x72, 0x67, 0x75, 0x6D, 0x65, 0x6E, 0x74, 0x4C, 0x69, 0x73, 0x74, 0x3E, 0x0D, 0x0A, \r
109   0x20, 0x20, 0x3C, 0x61, 0x72, 0x67, 0x75, 0x6D, 0x65, 0x6E, 0x74, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x6E, 0x61, 0x6D, \r
110   0x65, 0x3E, 0x6E, 0x65, 0x77, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x56, 0x61, 0x6C, 0x75, 0x65, 0x3C, 0x2F, 0x6E, 0x61, \r
111   0x6D, 0x65, 0x3E, 0x20, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x3E, 0x69, \r
112   0x6E, 0x3C, 0x2F, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x3E, 0x20, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x72, \r
113   0x65, 0x6C, 0x61, 0x74, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6C, 0x65, 0x3E, \r
114   0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x3C, 0x2F, 0x72, 0x65, 0x6C, 0x61, 0x74, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, \r
115   0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6C, 0x65, 0x3E, 0x20, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x2F, 0x61, 0x72, 0x67, 0x75, \r
116   0x6D, 0x65, 0x6E, 0x74, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x2F, 0x61, 0x72, 0x67, 0x75, 0x6D, 0x65, 0x6E, 0x74, 0x4C, \r
117   0x69, 0x73, 0x74, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x2F, 0x61, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x3E, 0x0D, 0x0A, 0x20, \r
118   0x20, 0x3C, 0x2F, 0x61, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x4C, 0x69, 0x73, 0x74, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x73, \r
119   0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x54, 0x61, 0x62, 0x6C, 0x65, 0x3E, 0x0D, 0x0A, 0x20, \r
120   0x20, 0x3C, 0x73, 0x74, 0x61, 0x74, 0x65, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6C, 0x65, 0x20, 0x73, 0x65, 0x6E, 0x64, \r
121   0x45, 0x76, 0x65, 0x6E, 0x74, 0x73, 0x3D, 0x22, 0x79, 0x65, 0x73, 0x22, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x6E, 0x61, \r
122   0x6D, 0x65, 0x3E, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x3C, 0x2F, 0x6E, 0x61, 0x6D, 0x65, 0x3E, 0x20, 0x0D, 0x0A, 0x20, \r
123   0x20, 0x3C, 0x64, 0x61, 0x74, 0x61, 0x54, 0x79, 0x70, 0x65, 0x3E, 0x62, 0x6F, 0x6F, 0x6C, 0x65, 0x61, 0x6E, 0x3C, 0x2F, \r
124   0x64, 0x61, 0x74, 0x61, 0x54, 0x79, 0x70, 0x65, 0x3E, 0x20, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x2F, 0x73, 0x74, 0x61, 0x74, \r
125   0x65, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6C, 0x65, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x73, 0x74, 0x61, 0x74, 0x65, \r
126   0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6C, 0x65, 0x20, 0x73, 0x65, 0x6E, 0x64, 0x45, 0x76, 0x65, 0x6E, 0x74, 0x73, 0x3D, \r
127   0x22, 0x6E, 0x6F, 0x22, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x6E, 0x61, 0x6D, 0x65, 0x3E, 0x54, 0x61, 0x72, 0x67, 0x65, \r
128   0x74, 0x3C, 0x2F, 0x6E, 0x61, 0x6D, 0x65, 0x3E, 0x20, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x64, 0x61, 0x74, 0x61, 0x54, 0x79, \r
129   0x70, 0x65, 0x3E, 0x62, 0x6F, 0x6F, 0x6C, 0x65, 0x61, 0x6E, 0x3C, 0x2F, 0x64, 0x61, 0x74, 0x61, 0x54, 0x79, 0x70, 0x65, \r
130   0x3E, 0x20, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x2F, 0x73, 0x74, 0x61, 0x74, 0x65, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6C, \r
131   0x65, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x2F, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, \r
132   0x54, 0x61, 0x62, 0x6C, 0x65, 0x3E, 0x0D, 0x0A, 0x20, 0x20, 0x3C, 0x2F, 0x73, 0x63, 0x70, 0x64, 0x3E\r
133 };\r