graphics/wserv/AnimPlugin/src/T_AnimProc.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 // 
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "T_AnimProc.h"
       
    17 #include "T_AnimDef.h"
       
    18 
       
    19 #define KMaxBufSize 250
       
    20 
       
    21 _LIT(KLim1,";");
       
    22 _LIT(KLim2,",");
       
    23 
       
    24 _LIT8(KSyncSecond,"ESyncSecond");
       
    25 _LIT8(KSyncMinute,"ESyncMinute");
       
    26 _LIT8(KSyncFlash,"ESyncFlash");
       
    27 _LIT8(KSyncNone,"ESyncNone");
       
    28 
       
    29 
       
    30 CAnimProc::CAnimProc(CTestAnimDll* aDll,TInt aType)
       
    31 	{
       
    32 	for (TInt i=0;i<KAnimTimeSize;i++)
       
    33 		iAnimTime[i]=0;
       
    34 
       
    35 	iNewPoint.SetXY (0, 0);
       
    36 	iLastPoint.SetXY (0, 0);
       
    37 
       
    38 	iStepX=0;
       
    39 	iStepY=0;
       
    40 	iDll=aDll;
       
    41 	
       
    42 	iAnimType=aType;
       
    43 
       
    44 	}
       
    45 
       
    46 
       
    47 CAnimProc::~CAnimProc()
       
    48 	{
       
    49 	iLastCommand.Close();
       
    50 	}
       
    51 TInt CAnimProc::WriteLog(const TDesC& aInfo)
       
    52 	{
       
    53 	return iDll->WriteLog(aInfo);
       
    54 	}
       
    55 TInt CAnimProc::WriteLog(const TDesC8& aInfo)
       
    56 	{
       
    57 	return iDll->WriteLog(aInfo);
       
    58 	}
       
    59 
       
    60 
       
    61 
       
    62 void CAnimProc::ConvertParam(TDes8& buf, TAny *aArgs)
       
    63 	{
       
    64 	if ( aArgs)
       
    65 		{
       
    66 		buf.Zero();
       
    67 
       
    68 		TUint8* p=STATIC_CAST(TUint8*,aArgs);
       
    69 		TInt len=p[0];
       
    70 
       
    71 		if ( len>0)
       
    72 			buf.Copy (p+1, len);
       
    73 		}
       
    74 	}
       
    75 
       
    76 void CAnimProc::RecordLastCmd(TInt cmd)
       
    77 	{
       
    78 	iLastCommand.Format(_L("%d"),cmd);
       
    79 	}
       
    80 void CAnimProc::RecordLastCmd(TInt cmd,const TDesC8& str)
       
    81 	{
       
    82 	TBuf<KMaxBufSize> buf;
       
    83 	buf.Copy(str);
       
    84 	iLastCommand.Format(_L("%d %S"),cmd,&buf);
       
    85 	}
       
    86 void CAnimProc::RecordLastCmd(const TDesC8& str)
       
    87 	{
       
    88 	iLastCommand.Copy(str);
       
    89 	}
       
    90 TInt CAnimProc::CmdReply(MAnimGeneralFunctions* pFunc , TInt aOpcode,
       
    91 		TAny *aArgs)
       
    92 	{
       
    93 	TBuf<KMaxBufSize> logbuf;
       
    94 	TBuf<KMaxBufSize> msgbuf;
       
    95 	logbuf.Format (_L("CAnimProc::CmdReplyL %d"),aOpcode);
       
    96 	WriteLog(logbuf);
       
    97 	
       
    98 	TBuf8<KMaxBufSize> arg;		
       
    99 			
       
   100 	TInt ret,slot;
       
   101 	TBool msgexist=EFalse,argexist=ETrue,userpanic=EFalse;
       
   102 	
       
   103 	// check is msg exist
       
   104 	const RMessagePtr2 *msg=pFunc->Message();
       
   105 	if ( msg && !msg->IsNull())
       
   106 		{
       
   107 		for (TInt i=1;i<4;i++)
       
   108 			{
       
   109 			ret=msg->Read (i, msgbuf);
       
   110 			if ( ret==KErrNone)
       
   111 				{
       
   112 				slot=i;
       
   113 				msgexist=ETrue;
       
   114 				break;
       
   115 				}
       
   116 			}
       
   117 		}	
       
   118 
       
   119 	switch (aOpcode)
       
   120 		{		
       
   121 		case ECmdTestWithoutPara:
       
   122 			{	
       
   123 			argexist=EFalse;			
       
   124 			if (msgexist)	
       
   125 				{
       
   126 				RecordLastCmd (aOpcode);				
       
   127 				ret=msg->Write(slot,iLastCommand);	
       
   128 				// this function should only used for AsyncCommandReply, otherwise emulator will crash.
       
   129 				msg->Complete(KErrNone); 
       
   130 				}
       
   131 			break;
       
   132 			}
       
   133 		case ECmdTestWithPara:
       
   134 			{		
       
   135 			ConvertParam(arg, aArgs);
       
   136 			WriteLog(arg);		
       
   137 			if (msgexist)	
       
   138 				{
       
   139 				RecordLastCmd (aOpcode, arg);				
       
   140 				msg->Write(slot,iLastCommand);	
       
   141 				}
       
   142 			break;
       
   143 			}
       
   144 		case ECmdGetLast:
       
   145 			{
       
   146 			argexist=EFalse;
       
   147 			if (msgexist)	
       
   148 				{				
       
   149 				logbuf.Format (_L("send last command %S"),&iLastCommand);
       
   150 				WriteLog(logbuf);
       
   151 				msg->Write(slot,iLastCommand);	
       
   152 				}
       
   153 			else
       
   154 				userpanic=ETrue;				
       
   155 			break;
       
   156 			}
       
   157 		case ECmdSync:
       
   158 			{
       
   159 			ConvertParam(arg, aArgs);
       
   160 			WriteLog(arg);			
       
   161 			MAnimGeneralFunctions::TAnimSync sync;
       
   162 			if (arg.Compare(KSyncSecond)==0)
       
   163 				sync=MAnimGeneralFunctions::ESyncSecond;
       
   164 			else if (arg.Compare(KSyncNone)==0)
       
   165 				sync=MAnimGeneralFunctions::ESyncNone;
       
   166 			else if (arg.Compare(KSyncFlash)==0)
       
   167 				sync=MAnimGeneralFunctions::ESyncFlash;
       
   168 			else if (arg.Compare(KSyncMinute)==0)
       
   169 				sync=MAnimGeneralFunctions::ESyncMinute;
       
   170 			else
       
   171 				{
       
   172 				userpanic=ETrue;
       
   173 				break;
       
   174 				}
       
   175 
       
   176 			pFunc->SetSync(sync);
       
   177 			break;
       
   178 			}
       
   179 		case ECmdGetAnimInterval:
       
   180 			{
       
   181 			argexist=EFalse;	
       
   182 			if (msgexist)
       
   183 				{
       
   184 					TInt i1,i2;
       
   185 					i1=(iAnimTime[1]-iAnimTime[0])/1000;
       
   186 					i2=(iAnimTime[2]-iAnimTime[1])/1000;
       
   187 					if (i1>i2)
       
   188 						{
       
   189 						TInt tmp;
       
   190 						tmp=i1;
       
   191 						i1=i2;
       
   192 						i2=tmp;
       
   193 						}
       
   194 					msgbuf.Format(_L("%d %d"),i1,i2);
       
   195 					msg->Write(slot,msgbuf);	
       
   196 				}
       
   197 			else
       
   198 				userpanic=ETrue;
       
   199 			break;
       
   200 			}		
       
   201 		default:		
       
   202 			{
       
   203 			userpanic=ETrue;
       
   204 			break;
       
   205 			}	
       
   206 		}
       
   207 	
       
   208 	if ( userpanic)
       
   209 		pFunc->Panic ();
       
   210 	else
       
   211 		{
       
   212 		if ( argexist)
       
   213 			RecordLastCmd (aOpcode, arg);
       
   214 		else
       
   215 			RecordLastCmd (aOpcode);
       
   216 		
       
   217 
       
   218 		}
       
   219 	return KErrNone ;
       
   220 	}
       
   221 
       
   222 CDesCArray* CAnimProc::ProcParamLC(const TDesC8& param)
       
   223 	{		
       
   224 	CDesCArrayFlat * ary= new (ELeave)  CDesCArrayFlat(2);   
       
   225 	CleanupStack::PushL(ary);
       
   226 	if ( param.Length ()>0)
       
   227 		{
       
   228 		TBuf<KMaxBufSize> buf;
       
   229 		TBuf<KMaxBufSize> tmp;
       
   230 		buf.Copy(param);
       
   231 
       
   232 		TInt idx;
       
   233 
       
   234 		do
       
   235 			{
       
   236 			idx=buf.Find(KLim1);
       
   237 			if (idx!=KErrNotFound )
       
   238 				{
       
   239 				
       
   240 				tmp.Copy(buf.Ptr(),idx);
       
   241 				ary->AppendL(tmp);					
       
   242 				buf.Delete(0,idx+1);
       
   243 				}
       
   244 			}
       
   245 
       
   246 		while (idx!=KErrNotFound);
       
   247 		
       
   248 		if (buf.Length()>0)
       
   249 			ary->AppendL(buf);	
       
   250 		}
       
   251 	return ary;
       
   252 	}
       
   253 TInt CAnimProc::GetIntFromStr(const TDesC& str,RIntArray& ary)
       
   254 	{	
       
   255 	ary.Reset();
       
   256 	TInt val;
       
   257 	
       
   258 	if ( str.Length ()>0)
       
   259 		{
       
   260 		TBuf<KMaxBufSize> buf;
       
   261 		TBuf<KMaxBufSize> tmp;
       
   262 		buf.Copy(str);
       
   263 
       
   264 		TInt idx;
       
   265 		do
       
   266 			{
       
   267 			idx=buf.Find(KLim2);
       
   268 			if (idx!=KErrNotFound )
       
   269 				{
       
   270 				
       
   271 				tmp.Copy(buf.Ptr(),idx);
       
   272 				TLex lex(tmp);
       
   273 				lex.Val(val);
       
   274 				ary.Append(val);
       
   275 				buf.Delete(0,idx+1);
       
   276 				}
       
   277 			}
       
   278 
       
   279 		while (idx!=KErrNotFound);
       
   280 		
       
   281 		if (buf.Length()>0)
       
   282 			{
       
   283 			TLex lex(buf);
       
   284 			lex.Val(val);
       
   285 			ary.Append(val);	
       
   286 			}
       
   287 		}	
       
   288 
       
   289 	return KErrNone;
       
   290 	}
       
   291 void CAnimProc::RecordAnimTime()
       
   292 	{	
       
   293 	TTime currentTime;
       
   294 	currentTime.HomeTime();	
       
   295 	
       
   296 	for (TInt i=0;i<KAnimTimeSize-1;i++)
       
   297 		iAnimTime[i]=iAnimTime[i+1];
       
   298 	
       
   299 	iAnimTime[KAnimTimeSize-1]=currentTime.Int64();	
       
   300 	}
       
   301 TInt CAnimProc::ConstructWinL(TAny *aArgs,MAnimGeneralFunctions* pFunc)
       
   302 	{		
       
   303 	iLastCommand.CreateL(KMaxBufSize);
       
   304 	
       
   305 	TInt ret,val;	
       
   306 	
       
   307 	TBuf8<KMaxBufSize> param;
       
   308 	ConvertParam(param, aArgs);
       
   309 	WriteLog(param);
       
   310 	
       
   311 	RecordLastCmd(iAnimType,param);
       
   312 	
       
   313 	TBuf<KMaxBufSize> buf;
       
   314 	
       
   315 	CDesCArray* ary=ProcParamLC(param);
       
   316 	TInt len=ary->Count();
       
   317 	
       
   318 	RIntArray intary;
       
   319 	CleanupClosePushL(intary);
       
   320 	
       
   321 	
       
   322 	for (TInt i=0;i<len;i++)
       
   323 		{
       
   324 		const TDesC& str=(*ary)[i];
       
   325 //		WriteLog (str);
       
   326 		switch (i)
       
   327 		{
       
   328 		case 0: //start point
       
   329 			{
       
   330 			GetIntFromStr(str,intary);
       
   331 			if (intary.Count()!=2)
       
   332 				ret=KErrArgument;
       
   333 			else
       
   334 				{
       
   335 				iLastPoint.SetXY( intary[0], intary[1] );
       
   336 			    iNewPoint.SetXY( intary[0], intary[1] );
       
   337 			    buf.Format(_L("start poinx x=%d y=%d"),iNewPoint.iX,iNewPoint.iY);
       
   338 			    WriteLog (buf);
       
   339 				}
       
   340 			break;
       
   341 			}
       
   342 		case 1: //step
       
   343 			{
       
   344 			GetIntFromStr(str,intary);
       
   345 			if (intary.Count()!=2)
       
   346 				ret=KErrArgument;
       
   347 			else
       
   348 				{
       
   349 				iStepX = intary[0];
       
   350 			    iStepY =intary[1];			  
       
   351 			    buf.Format(_L("step x=%d y=%d"),iStepX,iStepY);
       
   352 			    WriteLog (buf);
       
   353 				}
       
   354 			break;
       
   355 			}
       
   356 		case 2: //draw type
       
   357 			{
       
   358 			TLex lex(str);
       
   359 			lex.Val(val);
       
   360 			iDrawType=val;
       
   361 			buf.Format(_L("draw type=%d"),iDrawType);
       
   362 			WriteLog (buf);
       
   363 			break;
       
   364 			}			
       
   365 		case 3: //draw rect
       
   366 			{
       
   367 			GetIntFromStr(str,intary);
       
   368 			if (intary.Count()!=2)
       
   369 				ret=KErrArgument;
       
   370 			else
       
   371 				{
       
   372 				iSize.SetSize( intary[0], intary[1]);
       
   373 			    buf.Format(_L("draw rect width=%d height=%d"),iSize.iWidth,iSize.iHeight);
       
   374 			    WriteLog (buf);
       
   375 				}
       
   376 			break;
       
   377 			}
       
   378 		case 4: //pen color
       
   379 			{
       
   380 			GetIntFromStr(str,intary);
       
   381 			if (intary.Count()!=3)
       
   382 				ret=KErrArgument;
       
   383 			else
       
   384 				{
       
   385 				iColor.SetRed( intary[0]);
       
   386 				iColor.SetGreen( intary[1]);
       
   387 				iColor.SetBlue( intary[2]);
       
   388 			    buf.Format(_L("pen color r=%d g=%d b=%d"),iColor.Red(),iColor.Green(),iColor.Blue());
       
   389 			    WriteLog (buf);
       
   390 				}
       
   391 			break;
       
   392 			}
       
   393 		case 5: //pen size
       
   394 			{
       
   395 			GetIntFromStr(str,intary);
       
   396 			if (intary.Count()!=2)
       
   397 				ret=KErrArgument;
       
   398 			else
       
   399 				{
       
   400 				iPenSize.SetSize( intary[0], intary[1]);
       
   401 			    buf.Format(_L("pen size width=%d height=%d"),iPenSize.iWidth,iPenSize.iHeight);
       
   402 			    WriteLog (buf);
       
   403 				}
       
   404 			break;
       
   405 			}						
       
   406 		}
       
   407 		}
       
   408 	
       
   409 
       
   410     // initiates an initial position update
       
   411     iDrawn = ETrue;
       
   412  
       
   413     CleanupStack::PopAndDestroy(&intary);	
       
   414 	CleanupStack::PopAndDestroy(ary);	
       
   415 	
       
   416 	const RMessagePtr2 *msg=pFunc->Message();
       
   417 	if ( msg && !msg->IsNull())
       
   418 		{
       
   419 		TBuf<KMaxBufSize> msgbuf;
       
   420 		ret=msg->Read (1, msgbuf);
       
   421 		if ( ret==KErrNone)
       
   422 			{
       
   423 			msg->Write(1,iLastCommand);	
       
   424 			}
       
   425 		}	
       
   426 	
       
   427 	return ret;
       
   428 	}
       
   429