package protobuf;


import event.ModuleEvent;
import system.service.EventBusService;
import util.Log;
import protobuf.RblProto.*;

/**
 * Created by Peter Mösenthin.
 */
public class ProtobufInstructionResolver {

    public static final String DEBUG_TAG = ProtobufInstructionResolver.class.getSimpleName();

    public void resolve(RBLMessage message){
        RBLMessage.ActuatorType type = message.getRunInstruction().getActuator().getActuatorType();
        switch(type){
            case MODULE:
                runModuleInstruction(message);
                break;
            case SYSTEM:
                runSystemInstruction(message);
                break;
            case CLIENT:
                runClientInstruction(message);
        }
    }


    private void runModuleInstruction(RBLMessage message) {
        Log.add(DEBUG_TAG, "Running module instruction");
        RBLMessage.RunInstruction rI = message.getRunInstruction();
        if(rI != null){
            ModuleEvent mi = new ModuleEvent();
            mi.setType(rI.getInstruction().getModuleType().getNumber() + 1);
            mi.setModuleId(rI.getInstruction().getModuleId());
            mi.setInstructionId(rI.getInstruction().getInstructionId());
            mi.setParameters(rI.getInstruction().getParametersList());
            Log.add(DEBUG_TAG, "MT=" + mi.getType()
                    + " MID=" + mi.getModuleId()
                    + " IID=" + mi.getInstructionId()
                    + " INT_PARAMS=" + mi.getParameters());
            EventBusService.post(mi);
        }
    }

    private void runClientInstruction(RBLMessage message){
        Log.add(DEBUG_TAG, "Running client instruction");
    }

    private void runSystemInstruction(RBLMessage message){
        Log.add(DEBUG_TAG, "Running system instruction");
    }



}

@@ -13,16 +13,51 @@
 obuf;%0A%0A%0A
+import client.RaspberryLifeClient;%0A
 import e
@@ -70,24 +70,24 @@
 oduleEvent;%0A
-
 import syste
@@ -361,16 +361,44 @@
 resolve(
+RaspberryLifeClient client, 
 RBLMessa
@@ -786,32 +786,55 @@
 ction(message);%0A
+                break;%0A
         %7D%0A    %7D%0A
@@ -1070,17 +1070,17 @@
 eEvent m
-i
+e
  = new M
@@ -1102,25 +1102,25 @@
            m
-i
+e
 .setType(rI.
@@ -1179,25 +1179,25 @@
            m
-i
+e
 .setModuleId
@@ -1242,25 +1242,25 @@
            m
-i
+e
 .setInstruct
@@ -1319,17 +1319,17 @@
        m
-i
+e
 .setPara
@@ -1413,25 +1413,25 @@
 G, %22MT=%22 + m
-i
+e
 .getType()%0A 
@@ -1458,25 +1458,25 @@
  %22 MID=%22 + m
-i
+e
 .getModuleId
@@ -1507,25 +1507,25 @@
  %22 IID=%22 + m
-i
+e
 .getInstruct
@@ -1572,17 +1572,17 @@
 MS=%22 + m
-i
+e
 .getPara
@@ -1626,17 +1626,17 @@
 e.post(m
-i
+e
 );%0A     

add break statement