static_cast<const struct sr_datafeed_analog *>(
structure->payload));
break;
+ default:
+ payload = nullptr;
+ break;
}
}
shared_ptr<PacketPayload> Packet::get_payload()
{
- return payload->get_shared_pointer(this);
+ if (payload)
+ return payload->get_shared_pointer(this);
+ else
+ throw Error(SR_ERR_NA);
}
PacketPayload::PacketPayload()
}
Header::Header(const struct sr_datafeed_header *structure) :
- PacketPayload(),
- StructureWrapper<Packet, const struct sr_datafeed_header>(structure)
+ StructureWrapper<Packet, const struct sr_datafeed_header>(structure),
+ PacketPayload()
{
}
{
}
+shared_ptr<PacketPayload> Header::get_shared_pointer(Packet *parent)
+{
+ return static_pointer_cast<PacketPayload>(
+ static_pointer_cast<Header>(
+ StructureWrapper<Packet, const struct sr_datafeed_header>::
+ get_shared_pointer(parent)));
+}
+
int Header::get_feed_version()
{
return structure->feed_version;
}
Meta::Meta(const struct sr_datafeed_meta *structure) :
- PacketPayload(),
- StructureWrapper<Packet, const struct sr_datafeed_meta>(structure)
+ StructureWrapper<Packet, const struct sr_datafeed_meta>(structure),
+ PacketPayload()
{
}
{
}
+shared_ptr<PacketPayload> Meta::get_shared_pointer(Packet *parent)
+{
+ return static_pointer_cast<PacketPayload>(
+ static_pointer_cast<Meta>(
+ StructureWrapper<Packet, const struct sr_datafeed_meta>::
+ get_shared_pointer(parent)));
+}
+
map<const ConfigKey *, Glib::VariantBase> Meta::get_config()
{
map<const ConfigKey *, Glib::VariantBase> result;
}
Logic::Logic(const struct sr_datafeed_logic *structure) :
- PacketPayload(),
- StructureWrapper<Packet, const struct sr_datafeed_logic>(structure)
+ StructureWrapper<Packet, const struct sr_datafeed_logic>(structure),
+ PacketPayload()
{
}
{
}
+shared_ptr<PacketPayload> Logic::get_shared_pointer(Packet *parent)
+{
+ return static_pointer_cast<PacketPayload>(
+ static_pointer_cast<Logic>(
+ StructureWrapper<Packet, const struct sr_datafeed_logic>::
+ get_shared_pointer(parent)));
+}
+
void *Logic::get_data_pointer()
{
return structure->data;
}
Analog::Analog(const struct sr_datafeed_analog *structure) :
- PacketPayload(),
- StructureWrapper<Packet, const struct sr_datafeed_analog>(structure)
+ StructureWrapper<Packet, const struct sr_datafeed_analog>(structure),
+ PacketPayload()
{
}
{
}
+shared_ptr<PacketPayload> Analog::get_shared_pointer(Packet *parent)
+{
+ return static_pointer_cast<PacketPayload>(
+ static_pointer_cast<Analog>(
+ StructureWrapper<Packet, const struct sr_datafeed_analog>::
+ get_shared_pointer(parent)));
+}
+
float *Analog::get_data_pointer()
{
return structure->data;
protected:
PacketPayload();
virtual ~PacketPayload() = 0;
- shared_ptr<PacketPayload> get_shared_pointer(Packet *parent) {
- return static_pointer_cast<PacketPayload>(get_shared_pointer(parent));
- }
+ virtual shared_ptr<PacketPayload> get_shared_pointer(Packet *parent) = 0;
/** Deleter needed to allow shared_ptr use with protected destructor. */
class Deleter
{
};
/** Payload of a datafeed header packet */
-class SR_API Header : public PacketPayload,
- public StructureWrapper<Packet, const struct sr_datafeed_header>
+class SR_API Header :
+ public StructureWrapper<Packet, const struct sr_datafeed_header>,
+ public PacketPayload
{
public:
/* Feed version number. */
protected:
Header(const struct sr_datafeed_header *structure);
~Header();
- const struct sr_datafeed_header *structure;
+ shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
friend class Packet;
};
/** Payload of a datafeed metadata packet */
-class SR_API Meta : public PacketPayload,
- public StructureWrapper<Packet, const struct sr_datafeed_meta>
+class SR_API Meta :
+ public StructureWrapper<Packet, const struct sr_datafeed_meta>,
+ public PacketPayload
{
public:
/* Mapping of (ConfigKey, value) pairs. */
protected:
Meta(const struct sr_datafeed_meta *structure);
~Meta();
- const struct sr_datafeed_meta *structure;
+ shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
map<const ConfigKey *, Glib::VariantBase> config;
friend class Packet;
};
/** Payload of a datafeed packet with logic data */
-class SR_API Logic : public PacketPayload,
- public StructureWrapper<Packet, const struct sr_datafeed_logic>
+class SR_API Logic :
+ public StructureWrapper<Packet, const struct sr_datafeed_logic>,
+ public PacketPayload
{
public:
/* Pointer to data. */
protected:
Logic(const struct sr_datafeed_logic *structure);
~Logic();
- const struct sr_datafeed_logic *structure;
+ shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
friend class Packet;
};
/** Payload of a datafeed packet with analog data */
-class SR_API Analog : public PacketPayload,
- public StructureWrapper<Packet, const struct sr_datafeed_analog>
+class SR_API Analog :
+ public StructureWrapper<Packet, const struct sr_datafeed_analog>,
+ public PacketPayload
{
public:
/** Pointer to data. */
protected:
Analog(const struct sr_datafeed_analog *structure);
~Analog();
- const struct sr_datafeed_analog *structure;
+ shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
friend class Packet;
};