1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include "qemu/osdep.h"
18#include "qemu/iov.h"
19
20#include "rocker.h"
21#include "rocker_world.h"
22
23struct world {
24 Rocker *r;
25 enum rocker_world_type type;
26 WorldOps *ops;
27};
28
29ssize_t world_ingress(World *world, uint32_t pport,
30 const struct iovec *iov, int iovcnt)
31{
32 if (world->ops->ig) {
33 return world->ops->ig(world, pport, iov, iovcnt);
34 }
35
36 return -1;
37}
38
39int world_do_cmd(World *world, DescInfo *info,
40 char *buf, uint16_t cmd, RockerTlv *cmd_info_tlv)
41{
42 if (world->ops->cmd) {
43 return world->ops->cmd(world, info, buf, cmd, cmd_info_tlv);
44 }
45
46 return -ROCKER_ENOTSUP;
47}
48
49World *world_alloc(Rocker *r, size_t sizeof_private,
50 enum rocker_world_type type, WorldOps *ops)
51{
52 World *w = g_malloc0(sizeof(World) + sizeof_private);
53
54 if (w) {
55 w->r = r;
56 w->type = type;
57 w->ops = ops;
58 if (w->ops->init) {
59 w->ops->init(w);
60 }
61 }
62
63 return w;
64}
65
66void world_free(World *world)
67{
68 if (world->ops->uninit) {
69 world->ops->uninit(world);
70 }
71 g_free(world);
72}
73
74void world_reset(World *world)
75{
76 if (world->ops->uninit) {
77 world->ops->uninit(world);
78 }
79 if (world->ops->init) {
80 world->ops->init(world);
81 }
82}
83
84void *world_private(World *world)
85{
86 return world + 1;
87}
88
89Rocker *world_rocker(World *world)
90{
91 return world->r;
92}
93
94enum rocker_world_type world_type(World *world)
95{
96 return world->type;
97}
98
99const char *world_name(World *world)
100{
101 return world->ops->name;
102}
103