1200 |
1200 |
g_free(type);
|
1201 |
1201 |
}
|
1202 |
1202 |
|
|
1203 |
static void qdev_get_link_property(DeviceState *dev, Visitor *v, void *opaque,
|
|
1204 |
const char *name, Error **errp)
|
|
1205 |
{
|
|
1206 |
DeviceState **child = opaque;
|
|
1207 |
gchar *path;
|
|
1208 |
|
|
1209 |
if (*child) {
|
|
1210 |
path = qdev_get_canonical_path(*child);
|
|
1211 |
visit_type_str(v, &path, name, errp);
|
|
1212 |
g_free(path);
|
|
1213 |
} else {
|
|
1214 |
path = (gchar *)"";
|
|
1215 |
visit_type_str(v, &path, name, errp);
|
|
1216 |
}
|
|
1217 |
}
|
|
1218 |
|
|
1219 |
static void qdev_set_link_property(DeviceState *dev, Visitor *v, void *opaque,
|
|
1220 |
const char *name, Error **errp)
|
|
1221 |
{
|
|
1222 |
DeviceState **child = opaque;
|
|
1223 |
bool ambiguous = false;
|
|
1224 |
const char *type;
|
|
1225 |
char *path;
|
|
1226 |
|
|
1227 |
type = qdev_property_get_type(dev, name, NULL);
|
|
1228 |
|
|
1229 |
visit_type_str(v, &path, name, errp);
|
|
1230 |
|
|
1231 |
if (*child) {
|
|
1232 |
qdev_unref(*child);
|
|
1233 |
}
|
|
1234 |
|
|
1235 |
if (strcmp(path, "") != 0) {
|
|
1236 |
DeviceState *target;
|
|
1237 |
|
|
1238 |
target = qdev_resolve_path(path, &ambiguous);
|
|
1239 |
if (target) {
|
|
1240 |
gchar *target_type;
|
|
1241 |
|
|
1242 |
target_type = g_strdup_printf("link<%s>", target->info->name);
|
|
1243 |
if (strcmp(target_type, type) == 0) {
|
|
1244 |
*child = target;
|
|
1245 |
qdev_ref(target);
|
|
1246 |
} else {
|
|
1247 |
error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, type);
|
|
1248 |
}
|
|
1249 |
|
|
1250 |
g_free(target_type);
|
|
1251 |
} else {
|
|
1252 |
error_set(errp, QERR_DEVICE_NOT_FOUND, path);
|
|
1253 |
}
|
|
1254 |
} else {
|
|
1255 |
*child = NULL;
|
|
1256 |
}
|
|
1257 |
|
|
1258 |
g_free(path);
|
|
1259 |
}
|
|
1260 |
|
|
1261 |
void qdev_property_add_link(DeviceState *dev, const char *name,
|
|
1262 |
const char *type, DeviceState **child,
|
|
1263 |
Error **errp)
|
|
1264 |
{
|
|
1265 |
gchar *full_type;
|
|
1266 |
|
|
1267 |
full_type = g_strdup_printf("link<%s>", type);
|
|
1268 |
|
|
1269 |
qdev_property_add(dev, name, full_type,
|
|
1270 |
qdev_get_link_property,
|
|
1271 |
qdev_set_link_property,
|
|
1272 |
NULL, child, errp);
|
|
1273 |
|
|
1274 |
g_free(full_type);
|
|
1275 |
}
|
|
1276 |
|
1203 |
1277 |
static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev)
|
1204 |
1278 |
{
|
1205 |
1279 |
DeviceProperty *prop;
|