graphicsapitest/graphicssvs/wserv/AnimPlugin/src/T_AnimProc.cpp
changeset 103 2717213c588a
parent 98 bf7481649c98
child 116 171fae344dd4
child 121 d72fc2aace31
child 187 9f66f99ee56f
equal deleted inserted replaced
98:bf7481649c98 103:2717213c588a
     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 "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-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 				tmp.Copy(buf.Ptr(),idx);
       
   271 				TLex lex(tmp);
       
   272 				lex.Val(val);
       
   273 				ary.Append(val);
       
   274 				buf.Delete(0,idx+1);
       
   275 				}
       
   276 			}
       
   277 
       
   278 		while (idx!=KErrNotFound);
       
   279 		
       
   280 		if (buf.Length()>0)
       
   281 			{
       
   282 			TLex lex(buf);
       
   283 			lex.Val(val);
       
   284 			ary.Append(val);	
       
   285 			}
       
   286 		}	
       
   287 
       
   288 	return KErrNone;
       
   289 	}
       
   290 void CAnimProc::RecordAnimTime()
       
   291 	{	
       
   292 	TTime currentTime;
       
   293 	currentTime.HomeTime();	
       
   294 	
       
   295 	for (TInt i=0;i<KAnimTimeSize-1;i++)
       
   296 		iAnimTime[i]=iAnimTime[i+1];
       
   297 	
       
   298 	iAnimTime[KAnimTimeSize-1]=currentTime.Int64();	
       
   299 	}
       
   300 TInt CAnimProc::ConstructWinL(TAny *aArgs,MAnimGeneralFunctions* pFunc)
       
   301 	{		
       
   302 	iLastCommand.CreateL(KMaxBufSize);
       
   303 	
       
   304 	TInt ret,val;	
       
   305 	
       
   306 	TBuf8<KMaxBufSize> param;
       
   307 	ConvertParam(param, aArgs);
       
   308 	WriteLog(param);
       
   309 	
       
   310 	RecordLastCmd(iAnimType,param);
       
   311 	
       
   312 	TBuf<KMaxBufSize> buf;
       
   313 	
       
   314 	CDesCArray* ary=ProcParamLC(param);
       
   315 	TInt len=ary->Count();
       
   316 	
       
   317 	RIntArray intary;
       
   318 	CleanupClosePushL(intary);
       
   319 	
       
   320 	
       
   321 	for (TInt i=0;i<len;i++)
       
   322 		{
       
   323 		const TDesC& str=(*ary)[i];
       
   324 //		WriteLog (str);
       
   325 		switch (i)
       
   326 		{
       
   327 		case 0: //start point
       
   328 			{
       
   329 			GetIntFromStr(str,intary);
       
   330 			if (intary.Count()!=2)
       
   331 				ret=KErrArgument;
       
   332 			else
       
   333 				{
       
   334 				iLastPoint.SetXY( intary[0], intary[1] );
       
   335 			    iNewPoint.SetXY( intary[0], intary[1] );
       
   336 			    buf.Format(_L("start poinx x=%d y=%d"),iNewPoint.iX,iNewPoint.iY);
       
   337 			    WriteLog (buf);
       
   338 				}
       
   339 			break;
       
   340 			}
       
   341 		case 1: //step
       
   342 			{
       
   343 			GetIntFromStr(str,intary);
       
   344 			if (intary.Count()!=2)
       
   345 				ret=KErrArgument;
       
   346 			else
       
   347 				{
       
   348 				iStepX = intary[0];
       
   349 			    iStepY =intary[1];			  
       
   350 			    buf.Format(_L("step x=%d y=%d"),iStepX,iStepY);
       
   351 			    WriteLog (buf);
       
   352 				}
       
   353 			break;
       
   354 			}
       
   355 		case 2: //draw type
       
   356 			{
       
   357 			TLex lex(str);
       
   358 			lex.Val(val);
       
   359 			iDrawType=val;
       
   360 			buf.Format(_L("draw type=%d"),iDrawType);
       
   361 			WriteLog (buf);
       
   362 			break;
       
   363 			}			
       
   364 		case 3: //draw rect
       
   365 			{
       
   366 			GetIntFromStr(str,intary);
       
   367 			if (intary.Count()!=2)
       
   368 				ret=KErrArgument;
       
   369 			else
       
   370 				{
       
   371 				iSize.SetSize( intary[0], intary[1]);
       
   372 			    buf.Format(_L("draw rect width=%d height=%d"),iSize.iWidth,iSize.iHeight);
       
   373 			    WriteLog (buf);
       
   374 				}
       
   375 			break;
       
   376 			}
       
   377 		case 4: //pen color
       
   378 			{
       
   379 			GetIntFromStr(str,intary);
       
   380 			if (intary.Count()!=3)
       
   381 				ret=KErrArgument;
       
   382 			else
       
   383 				{
       
   384 				iColor.SetRed( intary[0]);
       
   385 				iColor.SetGreen( intary[1]);
       
   386 				iColor.SetBlue( intary[2]);
       
   387 			    buf.Format(_L("pen color r=%d g=%d b=%d"),iColor.Red(),iColor.Green(),iColor.Blue());
       
   388 			    WriteLog (buf);
       
   389 				}
       
   390 			break;
       
   391 			}
       
   392 		case 5: //pen size
       
   393 			{
       
   394 			GetIntFromStr(str,intary);
       
   395 			if (intary.Count()!=2)
       
   396 				ret=KErrArgument;
       
   397 			else
       
   398 				{
       
   399 				iPenSize.SetSize( intary[0], intary[1]);
       
   400 			    buf.Format(_L("pen size width=%d height=%d"),iPenSize.iWidth,iPenSize.iHeight);
       
   401 			    WriteLog (buf);
       
   402 				}
       
   403 			break;
       
   404 			}						
       
   405 		}
       
   406 		}
       
   407 	
       
   408 
       
   409     // initiates an initial position update
       
   410     iDrawn = ETrue;
       
   411  
       
   412     CleanupStack::PopAndDestroy(&intary);	
       
   413 	CleanupStack::PopAndDestroy(ary);	
       
   414 	
       
   415 	const RMessagePtr2 *msg=pFunc->Message();
       
   416 	if ( msg && !msg->IsNull())
       
   417 		{
       
   418 		TBuf<KMaxBufSize> msgbuf;
       
   419 		ret=msg->Read (1, msgbuf);
       
   420 		if ( ret==KErrNone)
       
   421 			{
       
   422 			msg->Write(1,iLastCommand);	
       
   423 			}
       
   424 		}	
       
   425 	
       
   426 	return ret;
       
   427 	}
       
   428