
manager = None
modem = None
evas = None
mmedia = None

lb = None
rb = None
menu3 = None
menu4 = None
title = None
timer = None
day = None

# backgrounds
dialBg = None
depthBg = None
TopMenuBg=None

updComm = None
browserapp = None
mbox = None
vdciapp = None
btapp = None
ppp = None
dspg = None
#log = None

dectHandler = None
vmHandler = None
eaHandler = None
mmiDebug = None
SP_context = None
soundpath = None
TNP = None # TelephoneNumberPolicy
dectCallManager = None
myannapp = None
trapHandler = None

retry_update = 0

from setting import setting
import config
import status
from roxiadebug import *


def vdci_send_mesg(code1, code2 = None, chan1 = 0, chan2 = 0, \
					mesg1 = None, mesg2 = None, mesg3 = None, mesg4 = None, mesg5 = None, \
					mesg6 = None, mesg7 = None, mesg8 = None, mesg9 = None):
	if vdciapp:
		vdciapp.send_mesg(code1, code2, chan1, chan2, mesg1, mesg2, mesg3, mesg4, mesg5, mesg6, mesg7, mesg8, mesg9)

def vdci_startup(ip_profile=True):
	from vdcisetting import vdci_setting
	import profile

#MMW	2008.0622	network error message to dect
	if dectCallManager.isSubcribedDect():
#		print 'wifi link up to DCT 0710!!!!!!!!!!!!!!!!!!!!!!!'
		dectCallManager.sendLinkUpReport()
		import time
		time.sleep(0.04)
#end of MMW


	if profile.ip_mode == 1:
		status.set_telnum()

	if ip_profile:
		parm_mesg2 = config.frame_rate_ip
	else:
		parm_mesg2 = config.frame_rate_pstn

	if ip_profile:
		if vdci_setting.tel_num:
			parm_mesg3 = 1 # startup with register
		else:
			parm_mesg3 = 0
	else:
		parm_mesg3 = 1

	mmiDebug.mmiTrace('ÃÊ±âÈ­ ½Ã µî·Ï --> DECTÀÇ ACK¿¡ »ó°ü¾øÀÌ ÁøÇà')
	dectCallManager.sendFirstRegistrationStartReport()
#	import time
#	time.sleep(0.5)

	if setting.subscriber == 1:
		QosSetValue = 160 # enable
	else:
		QosSetValue = 0 # disable

	vdci_send_mesg(code1=config.MESG_STARTUP, \
						mesg1=status.videocall_dimension, \
						mesg2=parm_mesg2[setting.video_fluency-1],\
						mesg3=parm_mesg3, \
						mesg5=QosSetValue, \
						mesg6=setting.video_bitrate)


# ka...2008.06.24:
def vdci_LinkUp():
	if vdciapp:
		vdci_send_mesg(code1='p', code2='l', mesg1='1')
def vdci_LinkDown():
	if vdciapp:
		vdci_send_mesg(code1='p', code2='l', mesg1='0')	
# ka...2008.06.24 ==

def vdci_play_tone(tone=config.PLAY_DIAL_TONE):
	#SP_context.SP_startPlayback()
	import vdciapp
	vdciapp.vdcitone_play_tone(tone)

def vdci_stop_tone():
	SP_context.SP_stopPlayback()
	import vdciapp
	vdciapp.vdcitone_stop_tone()

def vdci_send_dtmf(dtmf):
	if vdciapp:
		vdciapp.send_dtmf(dtmf)

def check_lanlink():

	def get_status():
		import os, utils
		try:
			os.system('/usr/local/bin/eth0_check_app > /tmp/eth0_status')
			fd = file('/tmp/eth0_status')
			t = fd.read()
			fd.close()
			utils.remove('/tmp/eth0_status')

			if t.find('UP') != -1:
				status.LanConnected = True
				return True
			elif t.find('DOWN') != -1:
				status.LanConnected = False
				return True
			else:
				#print '*** unknown lan link status ***'
				return False

		except:
			#print '*** [ERROR] check_lanlink() ***'
			return False

	if get_status() == False:
		#print '*** Retry check lan link status... ***'
		return get_status()

def peek_lanlink():
	# add shchun : similar to check_lanlink() but not to change status.LanConnected. 
	# 	if eth status is not clear, just assumes link is down.
	import os, utils, time
	try:
		os.system('/usr/local/bin/eth0_check_app > /tmp/eth0_status')
		time.sleep(0.1)
		fd = file('/tmp/eth0_status')
		t = fd.read()
		fd.close()
		utils.remove('/tmp/eth0_status')

		if t.find('UP') != -1:
			return True
		elif t.find('DOWN') != -1:
			return False
		else:
			print '[ERROR]Unknown lan link status, assume link down'
			return False
	except:
		print '[ERROR] exception when peek_lanlink ***'
		return True # org -- False

def peek_wifilink():
	# add shchun : corresponding function of peek_lanlink() when wifi.
	try:
		import os
		os.system('wlchecklink')

		fp = open('/tmp/wifi_getlinkstate')
		tmpState = fp.read()

		result = int(tmpState[0].strip())
		if result == 1:
			return True
		else:
			return False

	except:
		return False

# add shchun : for download..
manual_down_status=10
down=None 

# add shchun : for icmp check
tag_icmp_check=None
SoIP_changed=0

# add shchun : for idle errmsg
idle_errmsg= ''
#def utf82euckr(message):
#	result = ''
#	result = unicode(message,'utf-8').encode('euc-kr')
#	return result
#	
#def set_idle_errmsg(errmsg):
#	global idle_errmsg
#	debugLogC('IDLE_MSG: %s'%utf82euckr(errmsg))
#	idle_errmsg = errmsg


