text: var util=require("util"),async=require("async"),npmlog=require("npmlog"),luna=require("./luna"),path=require("path"),inspector=require("./inspect"),installer=require("./install"),novacom=require("./novacom"),os=require("os");
  (function(){var e=npmlog;e.heading="launcher";e.level="warn";var m={log:e,launch:function(a,k,f,h){if("function"!==typeof h)throw Error("Missing completion callback (next="+util.inspect(h)+")");var c=!1,l=this;a=a||{};async.series([function(b){"Hosted"===a.installMode?installer.list(a,function(a,g){for(index in g)if("com.sdk.ares.hostedapp"===g[index].id){c=!0;break}b()}):b()},function(b){"Hosted"===a.installMode?l.listRunningApp(a,null,function(d,g){for(index in g)if("com.sdk.ares.hostedapp"===g[index].id){l.close(a,
  "com.sdk.ares.hostedapp",null,b);return}b()}):b()},function(b){if("Hosted"!==a.installMode||c)b();else{var d=path.join(__dirname,"com.sdk.ares.hostedapp.ipk");a.appId=k;installer.install(a,d,b)}},function(b){a.nReplies=1;a.session=new novacom.Session(a.device,b)},function(b){"Hosted"===a.installMode?(a.session.runHostedAppServer(a.hostedurl,b),console.log("Ares Hosted App is now running...")):b()},function(b){if("Hosted"===a.installMode){var d=os.networkInterfaces(),g="";for(devName in d)for(var c=
  0;c<d[devName].length;c++){var e=d[devName][c];"IPv4"!==e.family||"127.0.0.1"===e.address||e.internal||(g=g||e.address,a.localIP=g)}d=a.session.getHostedAppServerPort();null==f&&(f={});f.hostedurl="http://"+g+":"+d+"/"}b()},function(b){var d=a.session.getDevice().lunaAddr.launch,g=d.returnValue.split(".");luna.send(a,d,{id:k,subscribe:!1,params:f},function(a,b){e.silly("launcher#launch#_launch():","lineObj:",a);var d=a;for(index=1;index<g.length;index++)d=d[g[index]];d?(e.verbose("launcher#launch#_launch():",
  "success"),b(null,{procId:d})):(e.verbose("launcher#launch#_launch():","failure"),b(Error("object format error")))},b)},function(b){a.inspect?(a.appId=k,a.running=!0,async.series([inspector.inspect.bind(inspector,a,null),function(){}],function(a){b(a)})):"Hosted"!=a.installMode&&b()}],function(a,d){e.verbose("launcher#launch()","err: ",a,"results:",d);var g=d[6];a||(g.msg="Launched application "+k);h(a,g)})},close:function(a,k,f,h){if("function"!==typeof h)throw Error("Missing completion callback (next="+
  util.inspect(h)+")");a=a||{};async.series([function(c){a.nReplies=1;a.session=new novacom.Session(a.device,c)},function(c){var h=a.session.getDevice(),b=h.lunaAddr.terminate,d=b.returnValue.split(".");"webos3"===h.type?c():luna.send(a,b,{id:k,subscribe:!1},function(a,b){e.silly("launcher#close#_close():","lineObj:",a);var c=a;for(index=1;index<d.length;index++)c=c[d[index]];c?(e.verbose("launcher#close#_close():","success"),b(null,{procId:c})):(e.verbose("launcher#close#_close():","failure"),b(Error("object format error")))},
  c)}],function(a,f){e.verbose("launcher#close()","err: ",a,"results:",f);var b=f[1];!a&&b&&(b.msg="Closed application "+k);h(a,b)})},listRunningApp:function(a,k,f){if("function"!==typeof f)throw Error("Missing completion callback (next="+util.inspect(f)+")");a=a||{};async.waterfall([function(e){a.nReplies=1;a.session=new novacom.Session(a.device,e)},function(h,c){var f=a.session.getDevice().lunaAddr.running,b=f.returnValue.split(".");if(!f||!b)return c(Error("not supported method to get running app information"));
  luna.send(a,f,{subscribe:!1},function(a,c){resultValue=a;for(index=1;index<b.length;index++)resultValue=resultValue[b[index]];resultValue=resultValue||[];a.returnValue?(e.verbose("launcher#listRunningApp():","success"),c(null,resultValue)):(e.verbose("launcher#listRunningApp():","failure"),c(Error("object format error")))},c)}],function(a,c){e.verbose("launcher#listRunningApp():","err:",a,"results:",c);f(a,c)})}};"undefined"!==typeof module&&module.exports&&(module.exports=m)})();
  