Exemple #1
0
ServerConfEditor::ServerConfEditor() : ModelEntityEditor< ::UI::ServerConfWrapper >() {
    // Create Custom Field
    initCustomField();

    // Change order
    initOrder();
    QString label;
    QString help;
    QList<IWidgetForm*> widget = getForm()->getWidgets();

    for (QList<IWidgetForm*>::iterator it = widget.begin(); it != widget.end(); it++) {
        Translate::instance()->group("server_editor_label");
        label = Translate::instance()->tr((*it)->getName());
        Translate::instance()->group("server_editor_help");
        help = Translate::instance()->tr((*it)->getName());
        (*it)->setLabel(label, help);
    }
    getForm()->getWidget("type")->setLabel("");
}
Exemple #2
0
void producer(void *arg)
{
	struct package *myPackage;
	myPackage = (struct package *)arg;

	pthread_t *consumers = myPackage->consumers;

	char *myFile;
	myFile = myPackage->orderFile;
	printf("myFile is %s\n",myFile);
	FILE *orders = fopen(myFile,"r");
	
	char c;
	int peopleCount;
	peopleCount = 0;
	while(c != EOF)
	{
		c = fgetc(orders);
		if(c == '\n')
			peopleCount++;
	}
	rewind(orders);

	int numOrders;
	numOrders = peopleCount;

	int orderLineSize = getMaxLineCount(orders);
 	rewind(orders);	
	char Line[orderLineSize];

	/* 
		Create an local array to hold all the orders. 
		Producer is responsible for populating the shared buffer.
		The reason for this is to keep track of all the mallocs performed and to free everything properly.
	*/


	char *title;
	char *priceTemp;
	char *idTemp;
	char *category;
	double price;
	int id;

	Order *localOrders[numOrders];

	int k;
	for(k = 0; k < numOrders; k++)
	{
		// Initialize the orders and place them into the array
		fgets(Line,orderLineSize,orders);
		Order *newOrder = malloc(sizeof(Order));

		title = strdup(strtok(Line,"|"));
		priceTemp = strdup(strtok(NULL,"|"));
		idTemp = strdup(strtok(NULL,"|"));
		category = strdup(strtok(NULL,"|"));
		
		price = atof(priceTemp);
		id = atoi(idTemp);
		
		initOrder(newOrder,title,price,id,category);

		localOrders[k] = newOrder;

		
	}



/*
	int orderCount;
	orderCount = 0;
*/
	while(ordersLeft != 0)
	{
		
		pthread_mutex_lock(&mutex);

		while(count == MAX)
		{
			printf("Producer about to sleep...\n");
			pthread_cond_signal(&dataAvailable);
			pthread_cond_wait(&spaceAvailable,&mutex);
		}

		printf("Producer: Inserting elements...\n");
	
		if(ordersLeft != 0)
		{	
			int i;
			for(i = 0; (i < MAX) && (ordersLeft != 0); i++)
			{
				if(sample[i] == NULL)
				{
					sample[i] = localOrders[ordersLeft-1];
					count++;
					pthread_mutex_lock(&orderLock);
					--ordersLeft;
					pthread_mutex_unlock(&orderLock);
				}
			}	


//			sleep(5);
		}
/*
		if(orderCount == 15)
		{
			done = 1;
			pthread_join(consumers[0],NULL);
		}
*/
		pthread_mutex_unlock(&mutex);


	}
	printf("Special exit of the producer...\n");
	pthread_mutex_lock(&mutex);
	done = 1;
	pthread_mutex_unlock(&mutex);

	printf("Attempting to wait on the consumers from the producer...\n");
//	pthread_join(consumers[0],NULL);
	printf("Successful join and exit\n");
	
/*
	int y;
	for(y = 0; y < 3; y++)
	{
		pthread_join(consumers[y],NULL);
	}
*/
	pthread_exit(0);
}