summaryrefslogtreecommitdiffstats
path: root/src/stateless/trex_stateless_api.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/stateless/trex_stateless_api.h')
-rw-r--r--src/stateless/trex_stateless_api.h40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/stateless/trex_stateless_api.h b/src/stateless/trex_stateless_api.h
index 6406a946..edd7b051 100644
--- a/src/stateless/trex_stateless_api.h
+++ b/src/stateless/trex_stateless_api.h
@@ -71,26 +71,48 @@ private:
*/
class TrexStateless {
public:
+
/**
- * create a T-Rex stateless object
- *
- * @author imarom (31-Aug-15)
+ * configure the stateless object singelton
+ * reconfiguration is not allowed
+ * an exception will be thrown
+ */
+ static void configure(uint8_t port_count);
+
+ /**
+ * singleton public get instance
*
- * @param port_count
*/
- TrexStateless(uint8_t port_count);
- ~TrexStateless();
+ static TrexStateless& get_instance() {
+ TrexStateless& instance = get_instance_internal();
+
+ if (!instance.m_is_configured) {
+ throw TrexException("object is not configured");
+ }
+
+ return instance;
+ }
TrexStatelessPort *get_port_by_id(uint8_t port_id);
uint8_t get_port_count();
protected:
+ TrexStateless();
+ ~TrexStateless();
+
+ static TrexStateless& get_instance_internal () {
+ static TrexStateless instance;
+ return instance;
+ }
+
+ /* c++ 2011 style singleton */
+ TrexStateless(TrexStateless const&) = delete;
+ void operator=(TrexStateless const&) = delete;
+
+ bool m_is_configured;
TrexStatelessPort **m_ports;
uint8_t m_port_count;
};
-/****** HACK *******/
-TrexStateless *get_trex_stateless();
-
#endif /* __TREX_STATELESS_API_H__ */