Exemple #1
0
void * sendAllUpdateToClient(void *data)
{
	int i = 0, j = 0;
	char isClientConnected = 0;
	int sockFd = 0;
	RESULT sendResult = G_FAIL;
	char clientId = *((char*)data);
	clntData_t clntData;
	CLIENT_DB *cdb = getClientDbInstance();
	if(!cdb)
	{
		LOG_ERROR("Error in client db instance");
		return;
	}
	if(clientId >= MAX_CLIENT)
	{
		LOG_ERROR("Invalid client Id, clntId =%d",clientId);
		return NULL;
	}
	if(cdb->clientState[clientId] == clnt_unregister_state)
	{
		LOG_ERROR("Client is already de registered, clntId =%d",clientId);
		return NULL;
	}
	PLAYLIST *pl = cdb->playList;
	// LOCK the playlist
	pthread_mutex_lock(&pl->playListLock);
	if(pl->playListSize <= 0)
	{
		LOG_MSG("Playlist is empty, nothing to update");
		pthread_mutex_unlock(&pl->playListLock);
		return NULL;
	}
	LIST_NODE *tempNode = NULL;
	for(i=0; i<MAX_CLIENT; i++)
	{
		// skip current client and unregistered client
		if((cdb->clientState[clientId] == clnt_unregister_state) || (i == clientId))
			continue;

		//skip client having not data
		if(pl->pList[i].totalNode == 0)
		{
			continue;
		}
		tempNode = pl->pList[i].first;
		for(j=0; j<pl->pList[i].totalNode; j++)
		{
			// create client message;
			clntData.header.clntId = clientId;
			clntData.header.msgId  = client_update_all;
			clntData.header.isLast = 0;
			clntData.header.token  = getNewToken();
			clntData.header.totalSize = 0;
			clntData.payLoad  = ((PlayListData*)(tempNode->data))->data;
			clntData.payloadSize = ((PlayListData*)(tempNode->data))->size;
			
			//if client is not connected connect with it
			if(!isClientConnected)
			{
				if(connectToClient(clientId, &sockFd) != G_OK)
				{
					LOG_ERROR("Unable to connect with client for sending update");
					break;
				}
				isClientConnected = 1;
			}
			if((sendResult = sendOneUpdate(&clntData, sockFd)) != G_OK)
			{
				LOG_ERROR("Sending update all fail");
				break;
			}
			tempNode = tempNode->next;
			clntData.payLoad = NULL;
			clntData.payloadSize = 0;
		}
		if(sendResult != G_OK)
		{
			break;
		}
	}
	if(isClientConnected)
	{
		closeSocket(sockFd);
	}
	pthread_mutex_unlock(&pl->playListLock);
	
}
Exemple #2
0
void FeedFetcher::fetch()
{
    getNewToken();
}