[Pcsclite-cvs-commit] PCSC/src pcscdaemon.c,1.38,1.39

sauveron-guest@quantz.debian.org sauveron-guest@quantz.debian.org
Tue, 16 Dec 2003 23:36:51 +0100


Update of /cvsroot/pcsclite/PCSC/src
In directory quantz:/tmp/cvs-serv3292/src

Modified Files:
	pcscdaemon.c 
Log Message:
Change the design of pcscdaemon. It gets the connection/disconnection from the client to the server (create/destroy a context), creates a new thread and then this thread will manage all the requests for this context

Index: pcscdaemon.c
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/pcscdaemon.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- pcscdaemon.c	30 Oct 2003 17:07:13 -0000	1.38
+++ pcscdaemon.c	16 Dec 2003 22:36:49 -0000	1.39
@@ -72,10 +72,12 @@
  */
 void SVCServiceRunLoop()
 {
-	sharedSegmentMsg msgStruct;
-	int currHandle, rsp;
-
-	currHandle = 0, rsp = 0;
+	int rsp;
+	LONG rv;
+	DWORD dwClientID;
+	
+	rsp = 0;
+	rv = 0;
 
 	/*
 	 * Initialize the comm structure 
@@ -89,13 +91,24 @@
 	}
 
 	/*
+	 * Initialize the contexts structure 
+	 */
+	rv = ContextsInitialize();
+
+	if (rv == -1)
+	{
+		DebugLogA("SVCServiceRunLoop: Error initializing pcscd.");
+		exit(-1);
+	}
+
+	/*
 	 * Solaris sends a SIGALRM and it is annoying 
 	 */
 
 	signal(SIGALRM, SIG_IGN);
 	signal(SIGPIPE, SIG_IGN);
 	signal(SIGHUP, SIG_IGN);	/* needed for Solaris. The signal is sent
-					 * when the shell is existed */
+				 * when the shell is existed */
 
 	/*
 	 * This function always returns zero 
@@ -116,58 +129,35 @@
 	while (TRUE)
 	{
 
-		switch (rsp = SHMProcessEvents(&msgStruct, 0))
+		switch (rsp = SHMProcessEventsServer(&dwClientID, 0))
 		{
 
 		case 0:
-			if (msgStruct.mtype == CMD_CLIENT_DIED)
-			{
-				/*
-				 * Clean up the dead client 
-				 */
-				SYS_MutexLock(&usbNotifierMutex);
-				MSGCleanupClient(&msgStruct);
-				SYS_MutexUnLock(&usbNotifierMutex);
-
-			} else
-			{
-				continue;
-			}
-
-			break;
+			DebugLogB("SVCServiceRunLoop: A new context thread creation is requested: %d", dwClientID);
+			rv = CreateContextThread(&dwClientID);
 
-		case 1:
-			if (msgStruct.mtype == CMD_FUNCTION)
-			{
-				/*
-				 * Command must be found 
-				 */
-				SYS_MutexLock(&usbNotifierMutex);
-				MSGFunctionDemarshall(&msgStruct);
-				rsp = SHMMessageSend(&msgStruct, msgStruct.request_id,
-					PCSCLITE_SERVER_ATTEMPTS);
-				SYS_MutexUnLock(&usbNotifierMutex);
-			} else
+ 			if (rv != SCARD_S_SUCCESS)
 			{
-				continue;
+				DebugLogA("SVCServiceRunLoop: Problem during the context thread creation");
+				AraKiri = 1;
 			}
 
 			break;
 
 		case 2:
 			/*
-			 * timeout in SHMProcessEvents(): do nothing
+			 * timeout in SHMProcessEventsServer(): do nothing
 			 * this is used to catch the Ctrl-C signal at some time when
 			 * nothing else happens
 			 */
 			break;
 
 		case -1:
-			DebugLogA("SVCServiceRun: Error in SHMProcessEvents");
+			DebugLogA("SVCServiceRunLoop: Error in SHMProcessEventsServer");
 			break;
 
 		default:
-			DebugLogB("SVCServiceRun: SHMProcessEvents unknown retval: %d",
+			DebugLogB("SVCServiceRunLoop: SHMProcessEventsServer unknown retval: %d",
 				rsp);
 			break;
 		}
@@ -454,7 +444,7 @@
 
 	SVCServiceRunLoop();
 
-	DebugLogA("pcscdaemon.c: main: SVCServiceRunLoop returned");
+	DebugLogA("main: SVCServiceRunLoop returned");
 	return EXIT_FAILURE;
 }