Tizen 2.0 Release
[framework/connectivity/bluez.git] / test / simple-service
1 #!/usr/bin/python
2
3 from __future__ import absolute_import, print_function, unicode_literals
4
5 import sys
6 import time
7 import dbus
8
9 xml = ' \
10 <?xml version="1.0" encoding="UTF-8" ?>         \
11 <record>                                        \
12   <attribute id="0x0001">                       \
13     <sequence>                                  \
14       <uuid value="0x1101"/>                    \
15     </sequence>                                 \
16   </attribute>                                  \
17                                                 \
18   <attribute id="0x0002">                       \
19      <uint32 value="0"/>                        \
20   </attribute>                                  \
21                                                 \
22   <attribute id="0x0003">                       \
23     <uuid value="00001101-0000-1000-8000-00805f9b34fb"/> \
24   </attribute>                                  \
25                                                 \
26   <attribute id="0x0004">                       \
27     <sequence>                                  \
28       <sequence>                                \
29         <uuid value="0x0100"/>                  \
30       </sequence>                               \
31       <sequence>                                \
32         <uuid value="0x0003"/>                  \
33         <uint8 value="23"/>                     \
34       </sequence>                               \
35     </sequence>                                 \
36   </attribute>                                  \
37                                                 \
38   <attribute id="0x0005">                       \
39     <sequence>                                  \
40       <uuid value="0x1002"/>                    \
41     </sequence>                                 \
42   </attribute>                                  \
43                                                 \
44   <attribute id="0x0006">                       \
45     <sequence>                                  \
46       <uint16 value="0x656e"/>                  \
47       <uint16 value="0x006a"/>                  \
48       <uint16 value="0x0100"/>                  \
49     </sequence>                                 \
50   </attribute>                                  \
51                                                 \
52   <attribute id="0x0007">                       \
53      <uint32 value="0"/>                        \
54   </attribute>                                  \
55                                                 \
56   <attribute id="0x0008">                       \
57      <uint8 value="0xff"/>                      \
58   </attribute>                                  \
59                                                 \
60   <attribute id="0x0009">                       \
61     <sequence>                                  \
62       <sequence>                                \
63         <uuid value="0x1101"/>                  \
64         <uint16 value="0x0100"/>                \
65       </sequence>                               \
66     </sequence>                                 \
67   </attribute>                                  \
68                                                 \
69   <attribute id="0x000a">                       \
70     <url value="http://www.bluez.org/"/>        \
71   </attribute>                                  \
72                                                 \
73   <attribute id="0x000b">                       \
74     <url value="http://www.bluez.org/"/>        \
75   </attribute>                                  \
76                                                 \
77   <attribute id="0x000c">                       \
78     <url value="http://www.bluez.org/"/>        \
79   </attribute>                                  \
80                                                 \
81   <attribute id="0x0100">                       \
82     <text value="Serial Port"/>                 \
83   </attribute>                                  \
84                                                 \
85   <attribute id="0x0101">                       \
86     <text value="Serial Port Service"/>         \
87   </attribute>                                  \
88                                                 \
89   <attribute id="0x0102">                       \
90      <text value="BlueZ"/>                      \
91   </attribute>                                  \
92                                                 \
93   <attribute id="0x0200">                       \
94     <sequence>                                  \
95       <uint16 value="0x0100"/>                  \
96     </sequence>                                 \
97   </attribute>                                  \
98                                                 \
99   <attribute id="0x0201">                       \
100      <uint32 value="0"/>                        \
101   </attribute>                                  \
102 </record>                                       \
103 '
104
105 bus = dbus.SystemBus()
106 manager = dbus.Interface(bus.get_object("org.bluez", "/"),
107                                                 "org.bluez.Manager")
108
109 if len(sys.argv) > 1:
110         path = manager.FindAdapter(sys.argv[1])
111 else:
112         path = manager.DefaultAdapter()
113
114 service = dbus.Interface(bus.get_object("org.bluez", path),
115                                                 "org.bluez.Service")
116
117 handle = service.AddRecord(xml)
118
119 print("Service record with handle 0x%04x added" % (handle))
120
121 print("Press CTRL-C to remove service record")
122
123 try:
124         time.sleep(1000)
125         print("Terminating session")
126 except:
127         pass
128
129 service.RemoveRecord(dbus.UInt32(handle))