1- import json
21import sys
32import threading
3+ from typing import List
4+
5+ import humps
46from nopdb import nopdb
57from vertx import EventBus
68
79from sourceplusplus .models .command .CommandType import CommandType
810from sourceplusplus .models .command .LiveInstrumentCommand import LiveInstrumentCommand
9- from sourceplusplus .models .command .LiveInstrumentContext import LiveInstrumentContext
1011from sourceplusplus .models .instrument .LiveBreakpoint import LiveBreakpoint
1112from sourceplusplus .models .instrument .LiveLog import LiveLog
1213from sourceplusplus .models .instrument .LiveMeter import LiveMeter
@@ -25,14 +26,15 @@ def __init__(self, eb: EventBus):
2526 LiveInstrumentRemote .dbg .start ()
2627 threading .settrace (sys .gettrace ())
2728
28- def add_live_instrument (self , context : LiveInstrumentContext , instrument_type : LiveInstrumentType ):
29- for i in context .instruments :
29+ def add_live_instrument (self , instruments : List [dict ]):
30+ for inst_dict in instruments :
31+ instrument_type : LiveInstrumentType = LiveInstrumentType .from_string (inst_dict ["type" ])
3032 if instrument_type == LiveInstrumentType .BREAKPOINT :
31- live_instrument = LiveBreakpoint .from_json ( i )
33+ live_instrument = LiveBreakpoint .from_dict ( inst_dict )
3234 elif instrument_type == LiveInstrumentType .LOG :
33- live_instrument = LiveLog .from_json ( i )
35+ live_instrument = LiveLog .from_dict ( inst_dict )
3436 else :
35- live_instrument = LiveMeter .from_json ( i )
37+ live_instrument = LiveMeter .from_dict ( inst_dict )
3638 bp = LiveInstrumentRemote .dbg .breakpoint (
3739 file = live_instrument .location .source [live_instrument .location .source .rfind ("/" ) + 1 :],
3840 line = live_instrument .location .line
@@ -41,46 +43,47 @@ def add_live_instrument(self, context: LiveInstrumentContext, instrument_type: L
4143 if instrument_type == LiveInstrumentType .BREAKPOINT :
4244 bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
4345 "ContextReceiver.apply_breakpoint('" + live_instrument .id + "',globals(),locals())" )
44- self .eb .publish (address = "spp.platform.status.live-breakpoint-applied" , body = json .loads (i ))
46+ body = humps .camelize (inst_dict )
47+ body ["meta" ] = inst_dict ["meta" ]
48+ self .eb .publish (address = "spp.processor.status.live-instrument-applied" , body = body )
4549 elif instrument_type == LiveInstrumentType .LOG :
4650 bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
4751 "ContextReceiver.apply_log('" + live_instrument .id + "',globals(),locals())" )
48- self .eb .publish (address = "spp.platform.status.live-log-applied" , body = json .loads (i ))
52+ body = humps .camelize (inst_dict )
53+ body ["meta" ] = inst_dict ["meta" ]
54+ self .eb .publish (address = "spp.processor.status.live-instrument-applied" , body = body )
4955 else :
5056 bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
5157 "ContextReceiver.apply_meter('" + live_instrument .id + "',globals(),locals())" )
52- self .eb .publish (address = "spp.platform.status.live-meter-applied" , body = json .loads (i ))
58+ body = humps .camelize (inst_dict )
59+ body ["meta" ] = inst_dict ["meta" ]
60+ self .eb .publish (address = "spp.processor.status.live-instrument-applied" , body = body )
5361
54- def remove_live_instrument (self , context : LiveInstrumentContext , type : LiveInstrumentType ):
62+ def remove_live_instrument (self , command : LiveInstrumentCommand ):
5563 print ("Removing live instrument(s)" )
56- for i in context .instruments :
64+ for inst_dict in command .instruments :
5765 if type == LiveInstrumentType .BREAKPOINT :
58- instrument = LiveBreakpoint .from_json ( i )
66+ instrument = LiveBreakpoint .from_dict ( inst_dict )
5967 elif type == LiveInstrumentType .LOG :
60- instrument = LiveLog .from_json ( i )
68+ instrument = LiveLog .from_dict ( inst_dict )
6169 else :
62- instrument = LiveMeter .from_json ( i )
70+ instrument = LiveMeter .from_dict ( inst_dict )
6371 try :
6472 LiveInstrumentRemote .dbg .remove_callback (LiveInstrumentRemote .instruments .pop (instrument .id )[0 ]._handle )
6573 except KeyError :
6674 pass
67- for i in context .locations :
68- loc = LiveSourceLocation .from_json (i )
75+ for inst_dict in command .locations :
76+ loc = LiveSourceLocation .from_json (inst_dict )
6977 delete = []
7078 for key , val in LiveInstrumentRemote .instruments .items ():
7179 if val [1 ].type == type and val [1 ].location == loc :
7280 delete .append (key )
73- for i in delete :
74- del LiveInstrumentRemote .instruments [i ]
81+ for inst_dict in delete :
82+ del LiveInstrumentRemote .instruments [inst_dict ]
7583
76- def handle_instrument_command (self , command : LiveInstrumentCommand , instrument_type : LiveInstrumentType ):
84+ def handle_instrument_command (self , command : LiveInstrumentCommand ):
7785 print ("Received command: " + command .command_type )
7886 if command .command_type == CommandType .ADD_LIVE_INSTRUMENT :
79- if instrument_type == LiveInstrumentType .BREAKPOINT :
80- self .add_live_instrument (command .context , LiveInstrumentType .BREAKPOINT )
81- elif instrument_type == LiveInstrumentType .LOG :
82- self .add_live_instrument (command .context , LiveInstrumentType .LOG )
83- else :
84- self .add_live_instrument (command .context , LiveInstrumentType .METER )
87+ self .add_live_instrument (command .instruments )
8588 elif command .command_type == CommandType .REMOVE_LIVE_INSTRUMENT :
86- self .remove_live_instrument (command . context , instrument_type )
89+ self .remove_live_instrument (command )
0 commit comments