1- import json
21import sys
32import threading
3+
44from nopdb import nopdb
55from vertx import EventBus
66
77from sourceplusplus .models .command .CommandType import CommandType
88from sourceplusplus .models .command .LiveInstrumentCommand import LiveInstrumentCommand
9- from sourceplusplus .models .command .LiveInstrumentContext import LiveInstrumentContext
109from sourceplusplus .models .instrument .LiveBreakpoint import LiveBreakpoint
1110from sourceplusplus .models .instrument .LiveLog import LiveLog
1211from sourceplusplus .models .instrument .LiveMeter import LiveMeter
@@ -25,14 +24,15 @@ def __init__(self, eb: EventBus):
2524 LiveInstrumentRemote .dbg .start ()
2625 threading .settrace (sys .gettrace ())
2726
28- def add_live_instrument (self , context : LiveInstrumentContext , instrument_type : LiveInstrumentType ):
29- for i in context .instruments :
27+ def add_live_instrument (self , command : LiveInstrumentCommand ):
28+ for inst_dict in command .instruments :
29+ instrument_type : LiveInstrumentType = LiveInstrumentType .from_string (inst_dict ["type" ])
3030 if instrument_type == LiveInstrumentType .BREAKPOINT :
31- live_instrument = LiveBreakpoint .from_json ( i )
31+ live_instrument = LiveBreakpoint .from_dict ( inst_dict )
3232 elif instrument_type == LiveInstrumentType .LOG :
33- live_instrument = LiveLog .from_json ( i )
33+ live_instrument = LiveLog .from_dict ( inst_dict )
3434 else :
35- live_instrument = LiveMeter .from_json ( i )
35+ live_instrument = LiveMeter .from_dict ( inst_dict )
3636 bp = LiveInstrumentRemote .dbg .breakpoint (
3737 file = live_instrument .location .source [live_instrument .location .source .rfind ("/" ) + 1 :],
3838 line = live_instrument .location .line
@@ -41,46 +41,41 @@ def add_live_instrument(self, context: LiveInstrumentContext, instrument_type: L
4141 if instrument_type == LiveInstrumentType .BREAKPOINT :
4242 bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
4343 "ContextReceiver.apply_breakpoint('" + live_instrument .id + "',globals(),locals())" )
44- self .eb .publish (address = "spp.platform .status.live-breakpoint -applied" , body = json . loads ( i ))
44+ self .eb .publish (address = "spp.processor .status.live-instrument -applied" , body = live_instrument . to_dict ( ))
4545 elif instrument_type == LiveInstrumentType .LOG :
4646 bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
4747 "ContextReceiver.apply_log('" + live_instrument .id + "',globals(),locals())" )
48- self .eb .publish (address = "spp.platform .status.live-log -applied" , body = json . loads ( i ))
48+ self .eb .publish (address = "spp.processor .status.live-instrument -applied" , body = live_instrument . to_dict ( ))
4949 else :
5050 bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
5151 "ContextReceiver.apply_meter('" + live_instrument .id + "',globals(),locals())" )
52- self .eb .publish (address = "spp.platform .status.live-meter -applied" , body = json . loads ( i ))
52+ self .eb .publish (address = "spp.processor .status.live-instrument -applied" , body = live_instrument . to_dict ( ))
5353
54- def remove_live_instrument (self , context : LiveInstrumentContext , type : LiveInstrumentType ):
54+ def remove_live_instrument (self , command : LiveInstrumentCommand ):
5555 print ("Removing live instrument(s)" )
56- for i in context .instruments :
56+ for inst_dict in command .instruments :
5757 if type == LiveInstrumentType .BREAKPOINT :
58- instrument = LiveBreakpoint .from_json ( i )
58+ instrument = LiveBreakpoint .from_dict ( inst_dict )
5959 elif type == LiveInstrumentType .LOG :
60- instrument = LiveLog .from_json ( i )
60+ instrument = LiveLog .from_dict ( inst_dict )
6161 else :
62- instrument = LiveMeter .from_json ( i )
62+ instrument = LiveMeter .from_dict ( inst_dict )
6363 try :
6464 LiveInstrumentRemote .dbg .remove_callback (LiveInstrumentRemote .instruments .pop (instrument .id )[0 ]._handle )
6565 except KeyError :
6666 pass
67- for i in context .locations :
68- loc = LiveSourceLocation .from_json (i )
67+ for inst_dict in command .locations :
68+ loc = LiveSourceLocation .from_json (inst_dict )
6969 delete = []
7070 for key , val in LiveInstrumentRemote .instruments .items ():
7171 if val [1 ].type == type and val [1 ].location == loc :
7272 delete .append (key )
73- for i in delete :
74- del LiveInstrumentRemote .instruments [i ]
73+ for inst_dict in delete :
74+ del LiveInstrumentRemote .instruments [inst_dict ]
7575
76- def handle_instrument_command (self , command : LiveInstrumentCommand , instrument_type : LiveInstrumentType ):
76+ def handle_instrument_command (self , command : LiveInstrumentCommand ):
7777 print ("Received command: " + command .command_type )
7878 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 )
79+ self .add_live_instrument (command )
8580 elif command .command_type == CommandType .REMOVE_LIVE_INSTRUMENT :
86- self .remove_live_instrument (command . context , instrument_type )
81+ self .remove_live_instrument (command )
0 commit comments