Module: AlWorker::Debug

Defined in:
lib/al_worker_debug.rb

Overview

デバッグサーバ

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) run(me)

デバッグ用IPCソケット、メソッド一式組み込み



20
21
22
23
24
25
# File 'lib/al_worker_debug.rb', line 20

def self.run( me )
  AlWorker.__send__( :include, AlWorker::Debug )
  @@ipcd = AlWorker::Ipc.new( File.join( me.workdir, me.name ) + ".debug" )
  @@ipcd.cb_prefix = "ipcd"
  @@ipcd.run( me )
end

Instance Method Details

- (Object) ipcd_a_call(sock, param)

メソッド呼び出し

(IPC) call function( args,… ) args by json array. call @me.method( args,… )



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/al_worker_debug.rb', line 136

def ipcd_a_call( sock, param )
  param = param[""]
  raise "please specify method."  if param == nil || param == ""
  if /^((@\w+)\.)?(\w+)\(?(.*)/ !~ param
    raise "parameter error"
  end
  obj,method,param = $2,$3,$4.strip
  param.chop!  if param[-1] == ")"
  param = JSON.parse( "[ #{param} ]" )

  if obj
    ret = instance_variable_get( obj ).__send__( method, *param )
  else
    ret = __send__( method, *param )
  end
  reply( sock, 200, "OK", ret.to_json )

rescue =>ex
  reply( sock, 400, "Bad Request. #{ex.message}" )
end

- (Object) ipcd_a_delete_variable(sock, param)

インスタンス変数 消去



110
111
112
113
114
115
116
# File 'lib/al_worker_debug.rb', line 110

def ipcd_a_delete_variable( sock, param )
  remove_instance_variable( param[""] )
  reply( sock, 200, "OK" )

rescue =>ex
  reply( sock, 400, "Bad Request. #{ex.message}" )
end

- (Object) ipcd_a_eval(sock, param)

Rubyスクリプトの評価



181
182
183
184
185
186
187
# File 'lib/al_worker_debug.rb', line 181

def ipcd_a_eval( sock, param )
  ret = eval( param[""] )
  reply( sock, 200, "OK", ret )

rescue =>ex
  reply( sock, 400, "Bad Request. #{ex.message}" )
end

- (Object) ipcd_a_get_variable(sock, param)

Note:

インスタンス変数 値取得

(IPC command)

get_variable @var


63
64
65
66
67
# File 'lib/al_worker_debug.rb', line 63

def ipcd_a_get_variable( sock, param )
  reply( sock, 200, "OK", instance_variable_get( param[""] ).to_json )
rescue =>ex
  reply( sock, 400, "Bad Request. #{ex.message}" )
end

- (Object) ipcd_a_list_methods(sock, param) Also known as: ipcd_a_list_method

メソッド一覧



122
123
124
125
# File 'lib/al_worker_debug.rb', line 122

def ipcd_a_list_methods( sock, param )
  methods = self.public_methods - Object.public_methods - AlWorker::Debug.public_instance_methods
  reply( sock, 200, "OK", methods.to_json )
end

- (Object) ipcd_a_list_variables(sock, req) Also known as: ipcd_a_list_variable

インスタンス変数 一覧



50
51
52
# File 'lib/al_worker_debug.rb', line 50

def ipcd_a_list_variables( sock, req )
  reply( sock, 200, "OK", instance_variables.to_json )
end

- (Object) ipcd_a_patch(sock, param)

動作(常駐)しているプログラムにパッチをあてる



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/al_worker_debug.rb', line 161

def ipcd_a_patch( sock, param )
  reply( sock, 100, "OK Let's go. Terminate ##END##" )
  file = Tempfile.new( "al_patch." )
  while txt = sock.gets
    break if txt.start_with?( "##END##" )
    file.puts txt
  end
  file.flush
  load( file.path )
  file.close!
  reply( sock, 200, "OK" )

rescue =>ex
  reply( sock, 400, "Bad Request. #{ex.message}" )
end

- (Object) ipcd_a_quit(sock, req)

quitコマンドの処理



31
32
33
34
# File 'lib/al_worker_debug.rb', line 31

def ipcd_a_quit( sock, req )
  reply( sock, 200, "OK quit." )
  return false
end

- (Object) ipcd_a_set_variables(sock, param) Also known as: ipcd_a_set_variable

Note:

インスタンス変数 値設定 (TODO) JSON object でデータを渡して複数の変数を一度にセット。 無くても良いかも。 (IDEA) set_variable @変数名 = JSONデータ 値の自由度はOK。 変数名に対する解析をどうする? ex) @var, @var evalは、使いたくない。

(IPC command)

set_variable @var=string
set_variable @var[3]=string        # 未実装(文字列しか入れられない)
set_variable @var["key"]=string    # 未実装
set_variable {"@var":"any data"}


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/al_worker_debug.rb', line 87

def ipcd_a_set_variables( sock, param )
  raise "Empty parameter."  if param.empty?

  if param[""]
    (k,v) = param[""].split( "=", 2 )
    raise "Parameter error."  if k == "" || v == nil || v == ""
    param = { k => v }
  end
    
  param.each do |k,v|
    instance_variable_set( k, v )
  end
  reply( sock, 200, "OK" )

rescue =>ex
  reply( sock, 400, "Bad Request. #{ex.message}" )
end

- (Object) ipcd_a_terminate(sock, req)

terminateコマンドの処理



40
41
42
43
44
# File 'lib/al_worker_debug.rb', line 40

def ipcd_a_terminate( sock, req )
  reply( sock, 200, "OK program terminate." )
  exit( 0 )
  return true
end