forked from adafruit/circuitpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteService.c
More file actions
126 lines (104 loc) · 5.36 KB
/
RemoteService.c
File metadata and controls
126 lines (104 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2019 Dan Halbert for Adafruit Industries
// SPDX-FileCopyrightText: Copyright (c) 2018 Artur Pacholec
// SPDX-FileCopyrightText: Copyright (c) 2017 Glenn Ruben Bakke
//
// SPDX-License-Identifier: MIT
#include <string.h>
#include "py/objproperty.h"
#include "py/runtime.h"
#include "shared-bindings/mdns/RemoteService.h"
//| class RemoteService:
//| """Encapsulates information about a remote service that was found during a search. This
//| object may only be created by a `mdns.Server`. It has no user-visible constructor."""
//|
//| def __init__(self) -> None:
//| """Cannot be instantiated directly. Use `mdns.Server.find`."""
//| ...
//|
//| hostname: str
//| """The hostname of the device (read-only),."""
static mp_obj_t mdns_remoteservice_get_hostname(mp_obj_t self_in) {
mdns_remoteservice_obj_t *self = MP_OBJ_TO_PTR(self_in);
const char *hostname = common_hal_mdns_remoteservice_get_hostname(self);
return mp_obj_new_str(hostname, strlen(hostname));
}
static MP_DEFINE_CONST_FUN_OBJ_1(mdns_remoteservice_get_hostname_obj, mdns_remoteservice_get_hostname);
MP_PROPERTY_GETTER(mdns_remoteservice_hostname_obj,
(mp_obj_t)&mdns_remoteservice_get_hostname_obj);
//| instance_name: str
//| """The human readable instance name for the service. (read-only)"""
static mp_obj_t remoteservice_get_instance_name(mp_obj_t self_in) {
mdns_remoteservice_obj_t *self = MP_OBJ_TO_PTR(self_in);
const char *instance_name = common_hal_mdns_remoteservice_get_instance_name(self);
return mp_obj_new_str(instance_name, strlen(instance_name));
}
static MP_DEFINE_CONST_FUN_OBJ_1(mdns_remoteservice_get_instance_name_obj, remoteservice_get_instance_name);
MP_PROPERTY_GETTER(mdns_remoteservice_instance_name_obj,
(mp_obj_t)&mdns_remoteservice_get_instance_name_obj);
//| service_type: str
//| """The service type string such as ``_http``. (read-only)"""
static mp_obj_t remoteservice_get_service_type(mp_obj_t self_in) {
mdns_remoteservice_obj_t *self = MP_OBJ_TO_PTR(self_in);
const char *service_type = common_hal_mdns_remoteservice_get_service_type(self);
return mp_obj_new_str(service_type, strlen(service_type));
}
static MP_DEFINE_CONST_FUN_OBJ_1(mdns_remoteservice_get_service_type_obj, remoteservice_get_service_type);
MP_PROPERTY_GETTER(mdns_remoteservice_service_type_obj,
(mp_obj_t)&mdns_remoteservice_get_service_type_obj);
//| protocol: str
//| """The protocol string such as ``_tcp``. (read-only)"""
static mp_obj_t remoteservice_get_protocol(mp_obj_t self_in) {
mdns_remoteservice_obj_t *self = MP_OBJ_TO_PTR(self_in);
const char *protocol = common_hal_mdns_remoteservice_get_protocol(self);
return mp_obj_new_str(protocol, strlen(protocol));
}
static MP_DEFINE_CONST_FUN_OBJ_1(mdns_remoteservice_get_protocol_obj, remoteservice_get_protocol);
MP_PROPERTY_GETTER(mdns_remoteservice_protocol_obj,
(mp_obj_t)&mdns_remoteservice_get_protocol_obj);
//| port: int
//| """Port number used for the service. (read-only)"""
static mp_obj_t remoteservice_get_port(mp_obj_t self_in) {
mdns_remoteservice_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_mdns_remoteservice_get_port(self));
}
static MP_DEFINE_CONST_FUN_OBJ_1(mdns_remoteservice_get_port_obj, remoteservice_get_port);
MP_PROPERTY_GETTER(mdns_remoteservice_port_obj,
(mp_obj_t)&mdns_remoteservice_get_port_obj);
//| ipv4_address: Optional[ipaddress.IPv4Address]
//| """IP v4 Address of the remote service. None if no A records are found."""
//|
static mp_obj_t _mdns_remoteservice_get_ipv4_address(mp_obj_t self) {
return common_hal_mdns_remoteservice_get_ipv4_address(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(mdns_remoteservice_get_ipv4_address_obj, _mdns_remoteservice_get_ipv4_address);
MP_PROPERTY_GETTER(mdns_remoteservice_ipv4_address_obj,
(mp_obj_t)&mdns_remoteservice_get_ipv4_address_obj);
//| def __del__(self) -> None:
//| """Deletes the RemoteService object."""
//| ...
//|
//|
static mp_obj_t mdns_remoteservice_obj_deinit(mp_obj_t self_in) {
mdns_remoteservice_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_mdns_remoteservice_deinit(self);
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_1(mdns_remoteservice_deinit_obj, mdns_remoteservice_obj_deinit);
static const mp_rom_map_elem_t mdns_remoteservice_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_hostname), MP_ROM_PTR(&mdns_remoteservice_hostname_obj) },
{ MP_ROM_QSTR(MP_QSTR_instance_name), MP_ROM_PTR(&mdns_remoteservice_instance_name_obj) },
{ MP_ROM_QSTR(MP_QSTR_service_type), MP_ROM_PTR(&mdns_remoteservice_service_type_obj) },
{ MP_ROM_QSTR(MP_QSTR_protocol), MP_ROM_PTR(&mdns_remoteservice_protocol_obj) },
{ MP_ROM_QSTR(MP_QSTR_port), MP_ROM_PTR(&mdns_remoteservice_port_obj) },
{ MP_ROM_QSTR(MP_QSTR_ipv4_address), MP_ROM_PTR(&mdns_remoteservice_ipv4_address_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mdns_remoteservice_deinit_obj) },
};
static MP_DEFINE_CONST_DICT(mdns_remoteservice_locals_dict, mdns_remoteservice_locals_dict_table);
MP_DEFINE_CONST_OBJ_TYPE(
mdns_remoteservice_type,
MP_QSTR_RemoteService,
MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS,
locals_dict, &mdns_remoteservice_locals_dict
);