[runtime] add getCurrentStateString and unexpectedMessage

These are virtual methods added to the UMLRTCapsule base class.

The user can override unexpectedMessage behaviour by linking in their
own versions.

The generated capsule class overrides getCurrentStateString.

Change-Id: I2d221f912c5bef44dbedc8fc0456dd5b4b4ad62f
Signed-off-by: Barry Maher <bmaher@gpinc.ca>
diff --git a/rts/include/umlrtcapsule.hh b/rts/include/umlrtcapsule.hh
index 8812ff5..00543ee 100644
--- a/rts/include/umlrtcapsule.hh
+++ b/rts/include/umlrtcapsule.hh
@@ -15,6 +15,7 @@
 #include "umlrtcontroller.hh"
 #include "umlrtcapsulerole.hh"
 #include "umlrtcapsuletocontrollermap.hh"
+#include "umlrtmessage.hh"
 #include "umlrtslot.hh"
 
 // This is the base class for each generated capsule that is defined in the model.
@@ -38,14 +39,19 @@
     virtual void inject ( const UMLRTMessage & msg ) = 0;
     virtual void unbindPort ( bool isBorder, int portIndex, int farEndIndex );
     virtual void bindPort ( bool isBorder, int portIndex, int farEndIndex );
+    virtual void unexpectedMessage ( ) const;
+    virtual const char * getCurrentStateString ( ) const { return ""; }
 
     const UMLRTCommsPort * * getBorderPorts ( ) const { return borderPorts; }
     const UMLRTCommsPort * getInternalPorts ( ) const { return internalPorts; }
     UMLRTSlot * getSlot ( ) const { return slot; }
-    const char * getName ( ) { return slot->name; }
-    size_t getIndex ( ) { return slot->capsuleIndex; }
-    UMLRTController::Error getError ( ) { return context()->getError(); }
+    const char * getName ( ) const { return slot->name; }
+    size_t getIndex ( ) const { return slot->capsuleIndex; }
+    UMLRTController::Error getError ( ) const { return context()->getError(); }
     const UMLRTCapsuleClass * getClass ( ) const { return capsuleClass; }
+    const UMLRTMessage * getMsg ( ) const { return msg; }
+
+    const UMLRTMessage * msg;
 
 protected:
 
diff --git a/rts/umlrt/umlrtcapsule.cc b/rts/umlrt/umlrtcapsule.cc
index f508e6f..daaa66b 100644
--- a/rts/umlrt/umlrtcapsule.cc
+++ b/rts/umlrt/umlrtcapsule.cc
@@ -13,6 +13,7 @@
 #include "umlrtframeservice.hh"
 #include "basedebug.hh"
 #include "basedebugtype.hh"
+#include <stdio.h>
 
 UMLRTCapsule::~UMLRTCapsule ( )
 {
@@ -20,7 +21,7 @@
     UMLRTCapsuleToControllerMap::removeCapsule(slot->name, this);
 }
 
-UMLRTCapsule::UMLRTCapsule ( const UMLRTRtsInterface * rtsif_, const UMLRTCapsuleClass * capsuleClass_, UMLRTSlot * slot, const UMLRTCommsPort * * borderPorts_, const UMLRTCommsPort * internalPorts_, bool isStatic_ ) : rtsif(rtsif_), capsuleClass(capsuleClass_), slot(slot), borderPorts(borderPorts_), internalPorts(internalPorts_), isStatic(isStatic_)
+UMLRTCapsule::UMLRTCapsule ( const UMLRTRtsInterface * rtsif_, const UMLRTCapsuleClass * capsuleClass_, UMLRTSlot * slot, const UMLRTCommsPort * * borderPorts_, const UMLRTCommsPort * internalPorts_, bool isStatic_ ) : msg(NULL), rtsif(rtsif_), capsuleClass(capsuleClass_), slot(slot), borderPorts(borderPorts_), internalPorts(internalPorts_), isStatic(isStatic_)
 {
     BDEBUG(BD_INSTANTIATE, "slot %s constructor\n", slot->name);
     UMLRTCapsuleToControllerMap::addCapsule(slot->name, this);
@@ -33,3 +34,9 @@
 void UMLRTCapsule::bindPort ( bool isBorder, int portIndex, int farEndIndex )
 {
 }
+
+void UMLRTCapsule::unexpectedMessage ( ) const
+{
+    fprintf( stderr, "capsule %s unexpected message on port %s protocol %s signal id %d\n",
+            getName(), getMsg()->destPort->role()->name, getMsg()->destPort->role()->protocol, getMsg()->signal.getId());
+}
diff --git a/rts/umlrt/umlrtcontroller.cc b/rts/umlrt/umlrtcontroller.cc
index 55716d8..c733ce1 100644
--- a/rts/umlrt/umlrtcontroller.cc
+++ b/rts/umlrt/umlrtcontroller.cc
@@ -459,6 +459,9 @@
 
                     base::debugLogData( BD_SIGNALDATA, msg->signal.getPayload(), msg->signal.getPayloadSize());
 
+                    // Set capsule message for this inject.
+                    msg->destPort->slot->capsule->msg = msg;
+
                     // Inject the signal into the capsule.
                     msg->destPort->slot->capsule->inject((UMLRTMessage)*msg);
                 }