Update Tizen 2.0 SDK source code
[sdk/tools/sdk-build.git] / src / build_server / JobLog.rb
index c46db48..e005207 100644 (file)
@@ -34,13 +34,67 @@ require "BuildComm.rb"
 
 class JobLog < Log
 
-       def initialize(job, path, stream_out)
-               super(path)
+       def initialize(job, stream_out)
+               if job.nil? then
+                       super(nil)
+               else
+                       if not File.exist? "#{job.server.path}/jobs/#{job.id}" then
+                               FileUtils.mkdir_p "#{job.server.path}/jobs/#{job.id}"
+                       end
+                       super("#{job.server.path}/jobs/#{job.id}/log")
+               end
                @parent_job=job
                @second_out = stream_out
        end
 
 
+       def set_second_out( out )
+               @second_out = out
+       end
+
+
+       def init
+               # comm-begin    
+               if not @second_out.nil? and not @second_out.closed? then
+                       BuildCommServer.send_begin(@second_out)
+               end
+       end
+
+
+       def close
+               # close communication
+               if not @second_out.nil? then
+                       begin 
+                               if  not @second_out.closed? then
+                                       BuildCommServer.send_end(@second_out)
+                               end
+                       rescue
+                       end
+                       BuildCommServer.disconnect(@second_out)
+               end
+
+               @second_out = nil       
+       end
+
+
+       def is_connected? 
+               if @second_out.nil? or @second_out.closed? then 
+                       return false
+               else
+                       return true
+               end
+       end
+
+
+       def has_second_out?
+               if @second_out.nil? then
+                       return false
+               else
+                       return true
+               end
+       end
+
+
        protected
 
        # overide
@@ -50,21 +104,17 @@ class JobLog < Log
                                BuildCommServer.send( @second_out, msg )
                        end
                rescue
-                       @parent_job.status="ERROR"
-                       close()
-                       error "Connection closed by remote client"
+                       # close second_out
+                       @second_out.close
+                       @second_out = nil
 
-                       # terminate job
-                       @parent_job.terminate
+                       error "Connection closed by remote client"
 
-                       # exit thread if independent worker thread
-                       if @parent_job.thread == Thread.current then
-                               error "Thread wiil be terminated"
-                               @parent_job.thread=nil
-                               Thread.exit
+                       # cancel parent job
+                       if not @parent_job.nil? and @parent_job.cancel_state == "NONE" then
+                               @parent_job.cancel_state = "INIT"
                        end
                end
        end     
 
-
 end