Mini Kabibi Habibi

Current Path : C:/Program Files/Smart Professional Surveillance System/PC-NVR/Common/Lua/
Upload File :
Current File : C:/Program Files/Smart Professional Surveillance System/PC-NVR/Common/Lua/ATMCtrl.lua

--   "$Id: ATMCtrl.lua 2416 2007-05-16 14:43:40Z yangbin $"
--   (c) Copyright 1992-2007, ZheJiang Dahua Information Technology Stock CO.LTD.
--                            All Rights Reserved
--
--	�� �� ��� ATMCtrl.lua
--	��    �:  ATM������ƽű�
-- ������еĴ���Lua�ű����Э��

local ATMCtrl = {};
local ATMProtocols = {};
local ATMProtocolName = {};
local protocolName = {};
local ProtocolNum = 0;
--���ص����Ĵ��ڽ���ű�
local function loadAtmScript(filename)
	local f,err = loadfile(filename);
	if f then
		local ret,protocol;
		ret,protocol = pcall(f);
		if ret then
			if protocol.Name == nil then
				print("load file failed");
				return;
			end;
			for i = 0, ProtocolNum do
				if protocol.Name == protocolName[i] then
					print("There is the same protocol name : ", protocol.Name);
					ATMProtocols[protocolName[i]] = protocol;
					protocolName[i] = protocol.Name;
					return;
				end;
			end;
			ATMProtocols[protocol.Name] = protocol;
			protocolName[ProtocolNum] = protocol.Name;
			--print("protocolName[", ProtocolNum, "]:", protocol.Name);
			--ATMProtocolName[ProtocolNum] = protocol.Name;
			ProtocolNum = ProtocolNum + 1;
			ATMCtrl.ProtocolNum = ProtocolNum;
		else
			err = protocol;
		end;
	end;
	
	if err then
		print(string.format("Error while loading ATM protocol:%s",err));
	end;
end;

--����ָ��Ŀ¼�µ��ļ�
local function LoadAtmProtocol(comPath)
	local ret, iter = pcall(lfs.dir, comPath);
	if ret then
		for filename in iter do
			if string.find(filename, "Str.lua") then
				loadAtmScript(comPath .. '/' .. filename);
			end;
		end;
	end;
end;

local function LoadATMScripts()
	ProtocolNum  = 0;
	for _, path in pairs(ATMCtrl.PathSet) do 
		LoadAtmProtocol(path);
	end
	
	for _, n in pairs(protocolName) do
		table.insert(ATMProtocolName, n);
	end
	table.sort(ATMProtocolName);
end

local function GetProtocolAttr(index)
	return ATMProtocolName[index];
end;

local function GetProtocolNum()
	return ProtocolNum;
end;


ATMCtrl.LoadATMScripts = LoadATMScripts;
ATMCtrl.ProtocolNum = ProtocolNum;
ATMCtrl.ATMProtocols = ATMProtocols;
ATMCtrl.GetProtocolAttr = GetProtocolAttr;
ATMCtrl.GetProtocolNum = GetProtocolNum;

return ATMCtrl;