Author: michael
Date: Mon Feb  1 07:59:00 2010
New Revision: 8442

URL: http://svn.slimdevices.com/jive?rev=8442&view=rev
Log:
Bug: n/a
Description: move some shared squeezeos specific code to jive.utils.squeezeos

Added:
    7.5/trunk/squeezeplay/src/squeezeplay_squeezeos/share/jive/utils/
    
7.5/trunk/squeezeplay/src/squeezeplay_squeezeos/share/jive/utils/squeezeos.lua
Modified:
    
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SetupStorage/SetupStorageApplet.lua
    
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterApplet.lua

Modified: 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SetupStorage/SetupStorageApplet.lua
URL: 
http://svn.slimdevices.com/jive/7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SetupStorage/SetupStorageApplet.lua?rev=8442&r1=8441&r2=8442&view=diff
==============================================================================
--- 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SetupStorage/SetupStorageApplet.lua
 (original)
+++ 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SetupStorage/SetupStorageApplet.lua
 Mon Feb  1 07:59:00 2010
@@ -7,6 +7,7 @@
 local io               = require("io")
 local math             = require("math")
 local string           = require("string")
+local squeezeos        = require("jive.utils.squeezeos")
 local table            = require("jive.utils.table")
 local lfs              = require("lfs")
 
@@ -22,7 +23,6 @@
 local Textarea         = require("jive.ui.Textarea")
 local Textinput        = require("jive.ui.Textinput")
 local Window           = require("jive.ui.Window")
-local squeezeos        = require("squeezeos_bsp")
 
 local debug            = require("jive.utils.debug")
 
@@ -163,34 +163,9 @@
 end
 
 function stopFileSharing(self)
-       self:_killByPidFile("/var/run/nmbd.pid")
-       self:_killByPidFile("/var/run/smbd.pid")
-end
-
-function _killByPidFile(self, file)
-       local pid = _readPidFile(file)
-
-       if pid then
-               squeezeos.kill(pid, 15)
-       end
-       os.remove(file)
-end
-
-function _readPidFile(file)
-       local fh = io.open(file, "r")
-
-       if fh == nil then
-               return
-       end
-
-       local pid = fh:read("*all")
-       fh:close()
-
-       log:debug("found pid " .. pid .. " reading " .. file)
-       
-       return pid
-end
-
+       squeezeos:kill("nmbd")
+       squeezeos:kill("smbd")
+end
 
 function _fileMatch(file, pattern)
        local fi = io.open(file, "r")

Modified: 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterApplet.lua
URL: 
http://svn.slimdevices.com/jive/7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterApplet.lua?rev=8442&r1=8441&r2=8442&view=diff
==============================================================================
--- 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterApplet.lua
 (original)
+++ 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterApplet.lua
 Mon Feb  1 07:59:00 2010
@@ -5,6 +5,7 @@
 local json             = require("json")
 local table            = require("jive.utils.table")
 local string           = require("jive.utils.string")
+local squeezeos        = require("jive.utils.squeezeos")
 local debug            = require("jive.utils.debug")
 
 local oo                     = require("loop.simple")
@@ -21,7 +22,6 @@
 local Task                   = require("jive.ui.Task")
 local Timer                  = require("jive.ui.Timer")
 local Window                 = require("jive.ui.Window")
-local squeezeos              = require("squeezeos_bsp")
 
 local appletManager          = appletManager
 local jiveMain               = jiveMain
@@ -270,10 +270,10 @@
                if self:serverRunning() then
 
                        -- stop server
-                       self:_killByPidFile("/var/run/squeezecenter.pid")
+                       squeezeos:killByPidFile("/var/run/squeezecenter.pid")
                        
                        -- stop resize helper daemon
-                       self:_killByPidFile("/var/run/gdresized.pid")
+                       squeezeos:killByPidFile("/var/run/gdresized.pid")
        
                        -- stop scanner
        --              local pid = _pidfor('scanner.pl')
@@ -285,15 +285,6 @@
        else
                os.execute("/etc/init.d/squeezecenter " .. action);
        end
-end
-
-function _killByPidFile(self, file)
-       local pid = _readPidFile(file)
-
-       if pid then
-               squeezeos.kill(pid, 15)
-       end
-       os.remove(file)
 end
 
 function _getStatusText(self)
@@ -1292,66 +1283,15 @@
 
 
 function serverRunning(self)
-       if _pidfor("squeezecenter") then
+       if squeezeos:pidfor("squeezecenter") then
                return true
        end
-       return self:processRunning('slimserver.pl')
+       return squeezeos:processRunning('slimserver.pl')
 end
 
 
 function scannerRunning(self)
-       return self:processRunning('scanner.pl')
-end
-
-
-function processRunning(self, process)
-       local pid = _pidfor(process)
-       if (pid ~= nil) then
-               return true
-       end
-       return false
-end
-
-
-function _pidfor(process)
-       local pid = _readPidFile("/var/run/" .. process .. ".pid")
-
-       if pid and squeezeos.kill(pid, 0) == 0 then
-               return pid
-       end
-       
-       local pattern = "%s*(%d+).*" .. process
-
-       log:debug("pattern is ", pattern)
-
-       local cmd = io.popen("/bin/ps -o pid,command")
-
-       if not cmd then
-               return nil
-       end
-
-       for line in cmd:lines() do
-               pid = string.match(line, pattern)
-               if pid then break end
-       end
-       cmd:close()
-
-       return pid
-end
-
-function _readPidFile(file)
-       local fh = io.open(file, "r")
-
-       if fh == nil then
-               return
-       end
-
-       local pid = fh:read("*all")
-       fh:close()
-
-       log:debug("found pid " .. pid .. " reading " .. file)
-       
-       return pid
+       return squeezeos:processRunning('scanner.pl')
 end
 
 

Added: 
7.5/trunk/squeezeplay/src/squeezeplay_squeezeos/share/jive/utils/squeezeos.lua
URL: 
http://svn.slimdevices.com/jive/7.5/trunk/squeezeplay/src/squeezeplay_squeezeos/share/jive/utils/squeezeos.lua?rev=8442&view=auto
==============================================================================
--- 
7.5/trunk/squeezeplay/src/squeezeplay_squeezeos/share/jive/utils/squeezeos.lua 
(added)
+++ 
7.5/trunk/squeezeplay/src/squeezeplay_squeezeos/share/jive/utils/squeezeos.lua 
Mon Feb  1 07:59:00 2010
@@ -1,0 +1,109 @@
+-----------------------------------------------------------------------------
+-- squeezeos.lua
+-----------------------------------------------------------------------------
+
+--[[
+=head1 NAME
+
+jive.util.squeezeos - some squeezeos specific system utilities
+
+=head1 DESCRIPTION
+
+Assorted utility functions for system process handling etc.
+
+=cut
+--]]
+
+local os        = require("os")
+local io        = require("io")
+local string    = require("string")
+local squeezeos = require("squeezeos_bsp")
+
+
+module(...)
+
+
+function processRunning(self, process)
+       local pid = self:pidfor(process)
+
+       if (pid ~= nil) then
+               return true
+       end
+       
+       return false
+end
+
+
+function pidfor(self, process)
+       local pidfile = "/var/run/" .. process .. ".pid"
+       local pid     = self:_readPidFile(pidfile)
+
+       if pid and squeezeos.kill(pid, 0) == 0 then
+               return pid, pidfile
+       end
+       
+       local cmd = io.popen("/bin/ps -o pid,command")
+
+       if not cmd then
+               return nil
+       end
+
+       local pattern = "%s*(%d+).*" .. process
+
+       for line in cmd:lines() do
+               pid = string.match(line, pattern)
+               if pid then break end
+       end
+       cmd:close()
+
+       return pid
+end
+
+
+function kill(self, process)
+       local pid, pidfile = self:pidfor(process)
+       
+       if pid then
+               squeezeos.kill(pid, 15)
+       end
+       
+       if pidfile then
+               os.remove(pidfile)
+       end
+end
+
+function killByPidFile(self, file)
+       local pid = self:_readPidFile(file)
+
+       if pid then
+               squeezeos.kill(pid, 15)
+       end
+       os.remove(file)
+end
+
+
+function _readPidFile(self, file)
+       local fh = io.open(file, "r")
+
+       if fh == nil then
+               return
+       end
+
+       local pid = fh:read("*all")
+       fh:close()
+       
+       return pid
+end
+
+
+--[[
+
+=head1 LICENSE
+
+Copyright 2010 Logitech. All Rights Reserved.
+
+This file is licensed under BSD. Please see the LICENSE file for details.
+
+=cut
+--]]
+

_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/jive-checkins

Reply via email to