transport: Retain knowledge of setting and clearing of events

The protocol layer now just filters the events based on the version of
the protocol in use, and leaves it to the transport layer to manage how
the resulting state is represented. For the moment this simply moves
manipulation of bmc_events in struct mbox_context down in to the
transport layer.

Change-Id: Iff1df934505dc9c769be3d376396d425fb4e8264
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/protocol.c b/protocol.c
index 58dad98..82c1ca7 100644
--- a/protocol.c
+++ b/protocol.c
@@ -33,10 +33,7 @@
 		break;
 	}
 
-	context->bmc_events |= (bmc_event & mask);
-	MSG_DBG("BMC Events set to: 0x%.2x\n", context->bmc_events);
-
-	return context->transport->flush_events(context);
+	return context->transport->set_events(context, (bmc_event & mask));
 }
 
 /*
@@ -48,10 +45,7 @@
  */
 int protocol_events_clear(struct mbox_context *context, uint8_t bmc_event)
 {
-	context->bmc_events &= ~bmc_event;
-	MSG_DBG("BMC Events clear to: 0x%.2x\n", context->bmc_events);
-
-	return context->transport->flush_events(context);
+	return context->transport->clear_events(context, bmc_event);
 }
 
 int protocol_v1_reset(struct mbox_context *context)
diff --git a/transport.h b/transport.h
index e6a4584..8d63b27 100644
--- a/transport.h
+++ b/transport.h
@@ -7,7 +7,8 @@
 struct mbox_context;
 
 struct transport_ops {
-	int (*flush_events)(struct mbox_context *context);
+	int (*set_events)(struct mbox_context *context, uint8_t events);
+	int (*clear_events)(struct mbox_context *context, uint8_t events);
 };
 
 #endif /* TRANSPORT_H */
diff --git a/transport_dbus.c b/transport_dbus.c
index 1d3f0cd..152dc95 100644
--- a/transport_dbus.c
+++ b/transport_dbus.c
@@ -11,7 +11,16 @@
 #include "protocol.h"
 #include "transport.h"
 
-int transport_dbus_flush_events(struct mbox_context *context)
+static int transport_dbus_set_events(struct mbox_context *context,
+				     uint8_t events)
+{
+	/* FIXME ! */
+	MSG_ERR("%s is unimplemented!\n", __func__);
+	return 0;
+}
+
+static int transport_dbus_clear_events(struct mbox_context *context,
+				       uint8_t events)
 {
 	/* FIXME ! */
 	MSG_ERR("%s is unimplemented!\n", __func__);
@@ -19,7 +28,8 @@
 }
 
 static const struct transport_ops transport_dbus_ops = {
-	.flush_events = transport_dbus_flush_events,
+	.set_events = transport_dbus_set_events,
+	.clear_events = transport_dbus_clear_events,
 };
 
 static int transport_dbus_get_info(sd_bus_message *m, void *userdata,
@@ -48,7 +58,7 @@
 
 	/* Switch transport to DBus. This is fine as DBus signals are async */
 	context->transport = &transport_dbus_ops;
-	context->transport->flush_events(context);
+	context->transport->set_events(context, context->bmc_events);
 
 	rc = sd_bus_message_new_method_return(m, &n);
 	if (rc < 0) {
diff --git a/transport_mbox.c b/transport_mbox.c
index 24d4734..671e1c4 100644
--- a/transport_mbox.c
+++ b/transport_mbox.c
@@ -121,8 +121,25 @@
 	return 0;
 }
 
+static int transport_mbox_set_events(struct mbox_context *context,
+				     uint8_t events)
+{
+	context->bmc_events |= events;
+
+	return transport_mbox_flush_events(context);
+}
+
+static int transport_mbox_clear_events(struct mbox_context *context,
+				       uint8_t events)
+{
+	context->bmc_events &= ~events;
+
+	return transport_mbox_flush_events(context);
+}
+
 static const struct transport_ops transport_mbox_ops = {
-	.flush_events = transport_mbox_flush_events,
+	.set_events = transport_mbox_set_events,
+	.clear_events = transport_mbox_clear_events,
 };
 
 /* Command Handlers */