memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanClientServer.cpp
branchRCL_3
changeset 21 52e343bb8f80
parent 20 ca8a1b6995f6
equal deleted inserted replaced
20:ca8a1b6995f6 21:52e343bb8f80
    94 
    94 
    95 	const TInt maxCount = params.iMaxCount;
    95 	const TInt maxCount = params.iMaxCount;
    96     NKern::ThreadEnterCS();
    96     NKern::ThreadEnterCS();
    97 
    97 
    98     DObject* serverHandle = (DObject*) params.iServerHandle;
    98     DObject* serverHandle = (DObject*) params.iServerHandle;
    99     DServer* server = static_cast<DServer*>(CheckedOpen(EMemSpyDriverContainerTypeServer, serverHandle));
    99     serverHandle = CheckIfObjectIsInContainer( EMemSpyDriverContainerTypeServer, serverHandle );
   100     if (server == NULL)
   100     if  ( serverHandle == NULL )
   101         {
   101         {
   102     	Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - END - server not found");
   102     	Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - END - server not found");
   103         NKern::ThreadLeaveCS();
   103         NKern::ThreadLeaveCS();
   104         return KErrNotFound;
   104         return KErrNotFound;
   105         }
   105         }
   106 
   106 
   107 	ResetTempHandles();
   107 	ResetTempHandles();
   108 
   108 
   109     NKern::LockSystem(); // Iterating session queue requires system lock
   109     DServer* server = (DServer*) serverHandle;
   110     // Iterate through this server's sessions, writing back session pointer (handle)
   110     NKern::LockSystem();
   111     // to client
   111 
   112     SDblQue& serverQueue = serverAdaption.GetSessionQueue( *server );
   112     r = server->Open();
   113     SDblQueLink* anchor = &serverQueue.iA;
   113     if  ( r == KErrNone )
   114     SDblQueLink* link = serverQueue.First();
   114         {
   115     while( link != anchor )
   115         // Iterate through this server's sessions, writing back session pointer (handle)
   116         {
   116         // to client
   117 		DSession* session = serverAdaption.GetSession( link );
   117         SDblQue& serverQueue = serverAdaption.GetSessionQueue( *server );
   118 
   118         SDblQueLink* anchor = &serverQueue.iA;
   119         // Found a match in the specified container. Write the object's handle (aka the object address)
   119         SDblQueLink* link = serverQueue.First();
   120         // back to the client address space
   120         while( link != anchor )
   121         if  ( session )
   121         	{
   122             {
   122 			DSession* session = serverAdaption.GetSession( link );
   123             AddTempHandle( session );
   123 
   124             }
   124             // Found a match in the specified container. Write the object's handle (aka the object address)
   125 
   125             // back to the client address space
   126         // Get next item
   126             if  ( session )
   127         link = link->iNext;
   127                 {
   128         }
   128                 AddTempHandle( session );
       
   129                 }
       
   130 
       
   131             // Get next item
       
   132             link = link->iNext;
       
   133             }
       
   134 
       
   135         NKern::ThreadEnterCS();
       
   136         TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - in CS..." ));
       
   137         //
       
   138 	    Kern::SafeClose( (DObject*&) server, NULL );
       
   139         TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - done safe close..." ));
       
   140         //
       
   141 	    NKern::ThreadLeaveCS();
       
   142         TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - left CS" ));
       
   143         }
       
   144     else
       
   145         {
       
   146     	Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles - error: %d opening server", r);
       
   147         }
       
   148 
   129     NKern::UnlockSystem();
   149     NKern::UnlockSystem();
   130 	server->Close(NULL);
       
   131 	NKern::ThreadLeaveCS();
       
   132 
   150 
   133     // This variable holds the number of handles that we have already
   151     // This variable holds the number of handles that we have already
   134 	// written to the client-side.
   152 	// written to the client-side.
   135 	TInt currentWriteIndex = 0;
   153 	TInt currentWriteIndex = 0;
   136 	const TInt handleCount = TempHandleCount();
   154 	const TInt handleCount = TempHandleCount();
   156             {
   174             {
   157             r = finalWrite;
   175             r = finalWrite;
   158             }
   176             }
   159         }
   177         }
   160 
   178 
       
   179 	NKern::ThreadLeaveCS();
   161 
   180 
   162 	TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - END - r: %d", r));
   181 	TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionHandles() - END - r: %d", r));
   163 	return r;
   182 	return r;
   164     }
   183     }
   165 
   184 
   178     DMemSpyDriverOSAdaptionDThread& threadAdaption = OSAdaption().DThread();
   197     DMemSpyDriverOSAdaptionDThread& threadAdaption = OSAdaption().DThread();
   179     DMemSpyDriverOSAdaptionDProcess& processAdaption = OSAdaption().DProcess();
   198     DMemSpyDriverOSAdaptionDProcess& processAdaption = OSAdaption().DProcess();
   180 
   199 
   181 	NKern::ThreadEnterCS();
   200 	NKern::ThreadEnterCS();
   182 
   201 
   183     DSession* session = (DSession*)CheckedOpen(EMemSpyDriverContainerTypeSession, (DObject*)aSessionHandle);
   202     DObject* sessionHandle = (DObject*) aSessionHandle;
   184     if (session == NULL )
   203     sessionHandle = CheckIfObjectIsInContainer( EMemSpyDriverContainerTypeSession, sessionHandle );
       
   204     if  ( sessionHandle == NULL )
   185         {
   205         {
   186     	Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - END - session not found");
   206     	Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - END - session not found");
   187         NKern::ThreadLeaveCS();
   207         NKern::ThreadLeaveCS();
   188         return KErrNotFound;
   208         return KErrNotFound;
   189         }
   209         }
   190 
   210 
       
   211     DSession* session = (DSession*) sessionHandle;
   191     session->FullName( params.iName );
   212     session->FullName( params.iName );
   192 
   213 
   193     // Get owner type and id
   214     NKern::LockSystem();
   194     DObject* sessionOwner = sessionAdaption.GetOwner( *session );
   215     r = session->Open();
   195     if  ( sessionOwner )
   216     if  ( r == KErrNone )
   196         {
   217         {
   197         const TObjectType objectType = sessionAdaption.GetObjectType( *sessionOwner );
   218         // Get owner type and id
   198         if  ( objectType == EProcess )
   219         DObject* sessionOwner = sessionAdaption.GetOwner( *session );
   199             {
   220         if  ( sessionOwner )
   200             DProcess* sessionProcess = (DProcess*) sessionOwner;
   221             {
   201             //
   222             const TObjectType objectType = sessionAdaption.GetObjectType( *sessionOwner );
   202             params.iOwnerId = processAdaption.GetId( *sessionProcess );
   223             if  ( objectType == EProcess )
   203             params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerProcess;
   224                 {
   204             }
   225                 DProcess* sessionProcess = (DProcess*) sessionOwner;
   205         else if ( objectType == EThread )
   226                 //
   206             {
   227                 params.iOwnerId = processAdaption.GetId( *sessionProcess );
   207             DThread* sessionThread = (DThread*) sessionOwner;
   228                 params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerProcess;
   208             //
   229                 }
   209             params.iOwnerId = threadAdaption.GetId( *sessionThread );
   230             else if ( objectType == EThread )
   210             params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerThread;
   231                 {
   211             }
   232                 DThread* sessionThread = (DThread*) sessionOwner;
       
   233                 //
       
   234                 params.iOwnerId = threadAdaption.GetId( *sessionThread );
       
   235                 params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerThread;
       
   236                 }
       
   237             }
       
   238         else
       
   239             {
       
   240             params.iOwnerId = -1;
       
   241             params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerNone;
       
   242             }
       
   243 
       
   244         // Other attributes
       
   245         params.iSessionType = sessionAdaption.GetSessionType( *session );
       
   246         params.iAddress = (TUint8*)session;
       
   247 
       
   248         NKern::ThreadEnterCS();
       
   249         TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - in CS..." ));
       
   250         //
       
   251 	    Kern::SafeClose( (DObject*&) session, NULL );
       
   252         TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - done safe close..." ));
       
   253         //
       
   254 	    NKern::ThreadLeaveCS();
       
   255         TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - left CS" ));
   212         }
   256         }
   213     else
   257     else
   214         {
   258         {
   215         params.iOwnerId = -1;
   259     	Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo - error: %d opening server", r);
   216         params.iOwnerType = TMemSpyDriverServerSessionInfo::EOwnerNone;
   260         }
   217         }
   261 
   218 
   262     NKern::UnlockSystem();
   219     // Other attributes
   263 
   220     params.iSessionType = sessionAdaption.GetSessionType( *session );
   264     if  ( r == KErrNone )
   221     params.iAddress = (TUint8*)session;
   265         {
   222 	session->Close(NULL);
   266         r = Kern::ThreadRawWrite( &ClientThread(), aParams, &params, sizeof(TMemSpyDriverServerSessionInfo) );
       
   267         }
       
   268 
   223 	NKern::ThreadLeaveCS();
   269 	NKern::ThreadLeaveCS();
   224     r = Kern::ThreadRawWrite( &ClientThread(), aParams, &params, sizeof(TMemSpyDriverServerSessionInfo) );
       
   225 
   270 
   226 	TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - END - r: %d", r));
   271 	TRACE( Kern::Printf("DMemSpyDriverLogChanClientServer::GetServerSessionInfo() - END - r: %d", r));
   227 	return r;
   272 	return r;
   228     }
   273     }