Exemplo n.º 1
0
 void componentConnected()
 {     
    CPPUNIT_ASSERT(!isMyVectorAttributeValid());   
                
    notifyOnMyVectorAttribute();                        
    requestInit();                
    requestStop();            
 }
Exemplo n.º 2
0
 void componentConnected()
 {     
    CPPUNIT_ASSERT(!isAnotherIntAttrValid());   
    CPPUNIT_ASSERT(!isMyIntAttrValid());
    
    if (mMode & CAttributesTest::MaskAnotherIntAttribute)
    {        
       notifyOnAnotherIntAttr();      
    }
    else
    {        
       notifyOnMyIntAttr();      
    }
    
    if (mMode == CAttributesTest::InitializeAttributeAfterStartup)          
    {
       requestInit();
    }
    
    if (mMode & CAttributesTest::UpdateEventsCount)
    {
       // five times so the event may be sent 5 times back (with 'always' notification type)
       requestInit();
       requestInit();
       requestInit();
       requestInit();
       requestInit();
    }
    
    if (mMode & CAttributesTest::Invalidate)
    {
       requestInit();
       requestInvalidate();
    }
          
    requestStop();            
 }
Exemplo n.º 3
0
 virtual void requestShutdown() {
   requestInit();
 }
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
    int listenfd, port, workersCounts, bufferSize, sffbsArg, clientlen;
    char *scheduling = malloc(7);
    struct sockaddr_in clientaddr;
	workers_resource *workerResources;
	int jobTicket = 0;
    getargs(&port, &workersCounts, &bufferSize, scheduling, &sffbsArg, argc, argv);
    
    scheduling = strdup(argv[4]);
    workerResources = (workers_resource*) malloc(sizeof(workers_resource));
    workerResources->groupHead = (node_request *) malloc(sizeof(node_request)); // for sff-bs
    
    // check if malloc fails
    if(workerResources == NULL) {
    	fprintf(stderr, "Malloc failed.");
    	exit(1);
    }
    
    workerResources->workerThreads = (worker_thread *) malloc(sizeof(worker_thread) * workersCounts);
    
    if(workerResources->workerThreads == NULL) {
    	fprintf(stderr, "Malloc failed.");
    	exit(1);
    }
    
    
    workerResources->bufferFront = NULL;
    workerResources->bufferEnd = NULL;
    workerResources->bufferFilled = 0;
    workerResources->bufferSize = bufferSize;
    
    // init lock and cv
    if(pthread_mutex_init(&(workerResources->bufferLock), NULL) != 0) {
    	fprintf(stderr, "Fail to initialize lock.");
    }

    if(pthread_cond_init(&(workerResources->bufferEmpty), NULL) != 0) {
    	fprintf(stderr, "Fail to initialize conditional variable.");
    }
    
    if(pthread_cond_init(&(workerResources->bufferNotEmpty), NULL) != 0) {
    	fprintf(stderr, "Fail to initialize conditional variable.");
    }
    // 
    // CS537: Create some threads...
    //
    int i;
    for(i = 0; i < workersCounts; i++) {
 		
    	worker_thread *tempWorker = (worker_thread *) malloc(sizeof(worker_thread));
    	tempWorker = &(workerResources->workerThreads[i]);
    	tempWorker->requestHandled = 0;
    	tempWorker->requestStatic = 0;
    	tempWorker->requestDynamic = 0;    
    	tempWorker->thread = (pthread_t *) malloc(sizeof(pthread_t));	
    	worker_id *workerId = (worker_id *) malloc(sizeof(worker_id));
    	workerId->id = i; // set the id
    	workerId->workerResources = workerResources;
    	
    	if(pthread_create(tempWorker->thread, NULL, workerThread, workerId) != 0) {
    		fprintf(stderr, "Cannot create thread.");
    	}
    }
    
    listenfd = Open_listenfd(port);
    
    while (1) {
		clientlen = sizeof(clientaddr);
		
		node_request *currRequest = (node_request *) malloc(sizeof(node_request));
		currRequest->conn = (conn_request*) malloc(sizeof(conn_request));
		currRequest->conn->fd = Accept(listenfd, (SA *)&clientaddr, (socklen_t *) &clientlen);
		requestInit(currRequest->conn); // set the conn with proper info
		
		//currRequest->next = NULL;
		
		// 
		// CS537: In general, don't handle the request in the main thread.
		// Save the relevant info in a buffer and have one of the worker threads 
		// do the work. However, for SFF, you may have to do a little work
		// here (e.g., a stat() on the filename) ...
		//
		
		pthread_mutex_lock(&(workerResources->bufferLock)); 
		
		while(workerResources->bufferFilled >= workerResources->bufferSize) {
			pthread_cond_wait(&(workerResources->bufferEmpty), &(workerResources->bufferLock));
		}
		
		// if nothing is in the buffer
		if(workerResources->bufferFilled == 0) {
		
			// fix for sffbs
			if(strcmp(scheduling, sffbs) == 0) {
				workerResources->groupHead = currRequest;
				jobTicket++;
			}
			
			workerResources->bufferFront = currRequest;
			workerResources->bufferEnd = currRequest;
			pthread_cond_signal(&(workerResources->bufferNotEmpty));
		} else {
		
			// in our sff, the shortest is in front of queue
			if(strcmp(scheduling, sff) == 0) {
				
				// put the request to the right position based on size
				node_request *temp = workerResources->bufferFront;
				
				if(temp->conn->size >= currRequest->conn->size) {
				
					currRequest->next = temp;
					workerResources->bufferFront = currRequest;
				
				} else {
								
					while(temp != NULL) {
						if(temp->next == NULL || currRequest->conn->size < temp->next->conn->size) {
							currRequest->next = temp->next;
							temp->next = currRequest;
							break;
						}
						temp = temp->next;
					}
				}
				
				
			} else if(strcmp(scheduling, fifo) == 0) { // if FIFO
				
				currRequest->next = NULL; // this will be last element in buffer queue
				workerResources->bufferEnd->next = currRequest; // add to the end
				workerResources->bufferEnd = currRequest; // update buffer end
				
			} else { //sff-bs
			
				if(jobTicket % sffbsArg == 0) { // get the head of new group
					workerResources->groupHead = currRequest;
					workerResources->bufferEnd->next = currRequest;
					workerResources->bufferEnd = currRequest;
				} else {
					reorderSff(workerResources, workerResources->groupHead, currRequest);
				}
				
				
				jobTicket++;
			}
		}
		
		workerResources->bufferFilled++; // increase the # of buffers filled
		pthread_mutex_unlock(&(workerResources->bufferLock));
		
    }

}