Function file_Initialize(msgPort As Object, userVariables As Object, bsp as Object)

    print "file_Initialize - entry"

    file = newfile(msgPort, userVariables, bsp)

    return file

End Function


Function newfile(msgPort As Object, userVariables As Object, bsp as Object)
	print "file"

	s = {}
	s.version = 0.4
	s.msgPort = msgPort
	s.userVariables = userVariables
	s.bsp = bsp
	s.ProcessEvent = file_ProcessEvent
	s.objectName = "file_object"
	s.debug  = false
	return s
End Function


Function file_ProcessEvent(event As Object) as boolean
	print "file plugin event: "; type(event)

	retval = false

	if type(event) = "roAssociativeArray" then
        if type(event["EventType"]) = "roString" then
             if (event["EventType"] = "SEND_PLUGIN_MESSAGE") then
                if event["PluginName"] = "file" then
                    pluginMessage$ = event["PluginMessage"]
		    print "SEND_PLUGIN/EVENT_MESSAGE:";pluginMessage$
                    retval = ParsefilePluginMsg(pluginMessage$, m)
                endif
            endif
        endif

	else if type(event) = "roTimerEvent" then

	end if

	return retval

End Function


Function ParsefilePluginMsg(Msg as string, s as object) as boolean

	retval  = false
	command = ""
	param =""
	sname$=""
		
	' convert the message to all lower case for easier string matching later
	msg = lcase(Msg)
	s.bsp.diagnostics.printdebug("Received Plugin message: "+msg)
	r = CreateObject("roRegex", "^file", "i")
	match=r.IsMatch(msg)

	if match then
		retval = true

		' split the string
		r2 = CreateObject("roRegex", "!", "i")
		fields=r2.split(msg)
		numFields = fields.count()
		if (numFields < 2) or (numFields > 2) then
			print "Incorrect number of fields for file command:";msg
			return retval
		else if (numFields = 2) then	'assumes command file!set
			command=fields[1]
			s.bsp.diagnostics.printdebug("2 fields: "+ command)
		end if
	end if

	if command = "debug" then
	    s.debug=true
	end if

	if command = "set" then

		if s.userVariables.DoesExist("current") then
			myvariable = s.userVariables.Lookup("currentfile")
			if myvariable <> invalid then 
				for each zone in s.bsp.sign.zonesHSM
					if zone.videoplayer <> invalid then 
						sname$ = zone.activestate.name$
						s.bsp.diagnostics.printdebug("State name:" + sname$)
					endif
				next
				myvariable.SetCurrentValue(sname$,true)	'sets value

			endif
		endif
	end if


	return retval
end Function






