示例#1
0
void DestroyPtrList(LPLIST lpList)
/***********************************************************************/
{
	LPTR lpNode;

	lpNode = (LPTR)ListGetHead(lpList);
	while (lpNode)
		{
		ListUnlink(lpList, lpNode);
		FreeUp(lpNode);
		lpNode = (LPTR)ListGetHead(lpList);
		}
}
示例#2
0
/*=========================================================================*/
SLPDSocket* SLPDSocketListRemove(SLPDSocketList* list, SLPDSocket* sock)
/* Unlinks and free()s the specified socket from the specified list        */
/*                                                                         */
/* list     - pointer to the SLPSocketList to unlink the socket from.      */
/*                                                                         */
/* sock     - pointer to the SLPSocket to unlink to the list               */
/*                                                                         */
/* Returns  - none                                                         */
/*=========================================================================*/
{
    ListUnlink((PListItem*)&list->head,(PListItem)sock);
    list->count = list->count - 1;
    return sock;
}         
示例#3
0
/*=========================================================================*/
SLPDAEntry* SLPDKnownDARemove(SLPDAEntry* entry)
/*                                                                         */
/* entry- (IN) pointer to entry to remove                                  */
/*                                                                         */
/* Returns: The previous SLPDAEntry (may be null).                         */
/*=========================================================================*/
{
    SLPDAEntry* del = entry;
    entry = (SLPDAEntry*)entry->listitem.next;
    ListUnlink((PListItem*)&G_KnownDAListHead,(PListItem)del);               
    if(entry == 0)
    {
        entry = G_KnownDAListHead;
    }
    SLPDAEntryFree(del);
    return entry;
}
示例#4
0
/*=========================================================================*/
int KnownDAConnect(const char* scopelist, 
                   int scopelistlen,
                   struct sockaddr_in* peeraddr,
                   struct timeval* timeout)
/*=========================================================================*/
{
    int                 sock;
    SLPDAEntry*         entry;
    
    /* TODO THIS FUNCTION MUST BE SYNCRONIZED !! */

    memset(peeraddr,0,sizeof(struct sockaddr_in));
    peeraddr->sin_family = AF_INET;
    peeraddr->sin_port   = htons(SLP_RESERVED_PORT);

    entry = G_KnownDAListHead;
    while(entry)
    {
        if(SLPStringListIntersect(entry->scopelistlen,
                                  entry->scopelist,
                                  scopelistlen,
                                  scopelist))
        {
            peeraddr->sin_addr   = entry->daaddr;
            sock = SLPNetworkConnectStream(peeraddr,timeout);
            if(sock >= 0)
            {
                return sock;
            }

            ListUnlink((PListItem*)&G_KnownDAListHead,(PListItem)entry);
            SLPDAEntryFree(entry);
        }
        
        entry = (SLPDAEntry*) entry->listitem.next;
    }

    return -1;
}
示例#5
0
/*=========================================================================*/
int SLPPropertySet(const char *pcName,
                    const char *pcValue)
/*=========================================================================*/
{
    int             pcNameSize; 
    int             pcValueSize;
    SLPProperty*    newProperty; 
    
    newProperty = Find(pcName);
    pcNameSize = strlen(pcName) + 1;
    pcValueSize = strlen(pcValue) + 1;
    
    if(newProperty == 0)
    {
        /* property does not exist in the list */
        newProperty = (SLPProperty*)malloc(sizeof(SLPProperty) + pcNameSize + pcValueSize);
        if(newProperty == 0)
        {
            /* out of memory */
            errno = ENOMEM;
            return -1;
        }

        /* set the pointers in the SLPProperty structure to point to areas of    */
        /* the previously allocated block of memory                              */
        newProperty->propertyName   = ((char*)newProperty) + sizeof(SLPProperty); 
        newProperty->propertyValue  = newProperty->propertyName + pcNameSize;
    
        /* copy the passed in name and value */
        memcpy(newProperty->propertyName,pcName,pcNameSize);
        memcpy(newProperty->propertyValue,pcValue,pcValueSize);
    
        /* Link the new property into the list */
        ListLink((PListItem*)&G_SLPPropertyListHead,(PListItem)newProperty);
    }
    else
    {    
        ListUnlink((PListItem*)&G_SLPPropertyListHead,(PListItem)newProperty);
        
        /* property already exists in the list */
        newProperty = (SLPProperty*)realloc(newProperty,sizeof(SLPProperty) + pcNameSize + pcValueSize);    
        if(newProperty == 0)
        {
            /* out of memory */
            errno = ENOMEM;
            return -1;
        }
       
        /* set the pointers in the SLPProperty structure to point to areas of    */
        /* the previously allocated block of memory                              */
        newProperty->propertyName   = ((char*)newProperty) + sizeof(SLPProperty); 
        newProperty->propertyValue  = newProperty->propertyName + pcNameSize;
    
        /* copy the passed in name and value */
        memcpy(newProperty->propertyName,pcName,pcNameSize);
        memcpy(newProperty->propertyValue,pcValue,pcValueSize);
        
        ListLink((PListItem*)&G_SLPPropertyListHead,(PListItem)newProperty);
    }
    
    return 0;
}
bool main_modesa(List *nodesList, List *linksList, Tree_t *tree, uint8_t sink_id, uint8_t sink_interfaces, \
                bool intMatrix[][MAX_NODES][NUM_CHANNELS], bool confMatrix[][MAX_NODES][NUM_CHANNELS], int8_t channel)
{
    uint16_t n_nodes = 0;

    /* Number of nodes in the network */
    n_nodes = ListLength(nodesList);

    /* Parameter iu, number of radio interfaces */
    uint8_t availableInterfaces[n_nodes];

    /* Set the number of interface in the sink node */
    Node_t *sink_node = getNode(sink_id, nodesList);
    sink_node->interfaces = sink_interfaces;

    /* Current time slot */
    uint16_t t = 0;

    /* In Modesa we use the parameter q of a node to keep track of how many packets the nodes
     * currently stores in its buffer */
    while (totalTraffic(nodesList) != 0)
    {
        /* Update priority of nodes and initialize the number of available interfaces */
        for (ListElem *elem = ListFirst(nodesList); elem != NULL; elem = ListNext(nodesList, elem))
        {
            /* Get the current node */
            Node_t *node = (Node_t *)elem->obj;

            /* Update the priority */
            node->priority = node->q * calculateParentRcv(node, tree);

            /* Initialize the number of interfaces */
            availableInterfaces[node->id] = node->interfaces;
        }

        /* Create an array of lists with conflicting nodes on channel c */
        List conflictLists[NUM_CHANNELS];
        for (uint8_t i = 0; i < NUM_CHANNELS; i++)
        {
            memset(&conflictLists[i], 0, sizeof(List));
            ListInit(&conflictLists[i]);
        }

        /* Create N, the list of nodes having data to transmit and sorted according to their priorities */
        List N; memset(&N, 0, sizeof(List)); ListInit(&N);
        createListNodeWithData(nodesList, &N);

        /* While N != 0 */
        while(ListLength(&N))
        {
            bool tx = false;
            bool nChannelReached = false;

            Node_t *selectedNode = NULL;
            Node_t *selectedParent = NULL;

            /* Remove nodes from N until we get a node with available interface and whose parent also has an interface */
            do
            {
                ListElem *elem = ListFirst(&N);

                if (elem == NULL)
                {
                    selectedNode = NULL;
                    break;
                }
                else
                {
                    selectedNode = (Node_t *)elem->obj;
                }
                ListUnlink(&N, elem);

                selectedParent = getParent(tree, selectedNode);
            } while (availableInterfaces[selectedNode->id] == 0 || availableInterfaces[selectedParent->id] == 0);

            if (selectedNode == NULL)
            {
                break;
            }

            uint8_t c = 0;

            /* Try to schedule until TX or nChannelReached */
            do
            {
                /* If selectedNode is not in the conflict list of channel c */
                if (!ListFind(&conflictLists[c], (void *)selectedNode))
                {
                    /* Node selectedNode transmits in slot t on channel c */
                    TimeSlot_t *ts = newTimeSlot(t+1, c, TS_TX, selectedParent, false);
                    ListAppend(&selectedNode->timeslots, (void *)ts);
                    ts = newTimeSlot(t+1, c, TS_RX, selectedNode, false);
                    ListAppend(&selectedParent->timeslots, (void *)ts);

                    /* Update the current traffic queue */
                    selectedNode->q--;
                    if (selectedParent->id != sink_id)
                    {
                        selectedParent->q++;
                    }

                    /* Update the number of available interfaces */
                    availableInterfaces[selectedNode->id]--;
                    availableInterfaces[selectedParent->id]--;

                    /* Update the list of conflicting nodes on channel c */
                    ListAppend(&conflictLists[c], (void *)selectedNode);
                    for (uint8_t i = 0; i < n_nodes; i++)
                    {
                        if (confMatrix[selectedNode->id][i][channel] == true)
                        {
                            Node_t *confNode = getNode(i, nodesList);
                            if (!ListFind(&conflictLists[c], (void *)confNode))
                            {
                                ListAppend(&conflictLists[c], (void *)confNode);
                            }
                        }
                    }

                    tx = true;
                }
                else
                {
                    if (c < NUM_CHANNELS)
                    {
                        /* Next channel */
                        c++;
                    }
                    else
                    {
                        /* No more available channels */
                        nChannelReached = true;
                    }
                }

            } while (!tx && !nChannelReached);
        }

        /* t = t + 1 */
        t++;
    }

    return (true);
}
示例#7
0
BOOL PlayMacro(LPCMDLIST lpCmdList, LPTSTR lpFileName, int nRepeat,
				BOOL fSequenceAll, LPLIST lpMacroList, HWND hParent,
				int PhotoCDResOverride, LPTSTR lpMacroName)
/***********************************************************************/
{
LPIMAGE lpImage;
LPCMDLIST lpNewList;
int nActivates, iCount;
ITEMID idCommand;
STRING szString, szAppName;
BOOL fError;
BOOL fSequence, fCmdSequence, fCopyPackets;
LIST MacroList;
LPCMDPKT lpCmdPkt, lpNextPkt;
MACROSETUP Setup;
COMMAND_TYPE CommandType;
HWND hDlg = NULL;

lpAbortProc = NULL;
if (!hParent)
	hParent = PictPubApp.Get_hWndAstral();

// see if we need to copy our packets
fCopyPackets = nRepeat > 1;

if (!lpMacroList)
	{
	// read in the entire macro file for faster processing
	if (!ReadMacro(lpFileName, &MacroList))
		return(FALSE);
	lpMacroList = &MacroList;
	}

// count the number of activates in the macro file
// because it affects sequencing
nActivates = CountType(lpMacroList, CT_ACTIVATE);

// turn of macro play mode and tell the world
MacroMode = MM_PLAY;
if ( AstralStrEx( IDS_APPNAME, szAppName, sizeof(szAppName) ) )
	{
	if ( AstralStrEx( IDS_MACROPLAY, szString, sizeof(szString) ) )
		{
		lstrcat( szAppName, szString );
		SetWindowText( PictPubApp.Get_hWndAstral(), szAppName );
		}
	}

// reset untitled number so that if a macro is played it
// can deal with untitled images the same
Control.UntitledNo = 0;

// If no command list passed in to work on (Macro Batch Mode)
// then get command list for active image
if (!lpCmdList)
	{
	if (lpImage = GetActiveImage())
		lpCmdList = lpImage->lpCmdList;
	else
		lpCmdList = NULL;
	}

// See if the macro contains any low res loads and
// if so ask to user if he'd like to convert them
// to hi res loads and if so do the convert
if (FindCommand(lpMacroList, IDS_CMD_LOWRESLOAD))
	if (AstralAffirm(IDS_CONVERTLOWRES))
		if (!ConvertLowResLoad(lpMacroList))
			{
			DestroyPacketList(lpMacroList);
			return(FALSE);
			}

// disable all mouse and keyboard input during macro play
EnableWindow(hParent, FALSE);

// if not in a threading environment and caller wants us
// to display a progress dialog, then set it up and do it
if (!Control.UseThreading)
	{
	iCount = ListGetCount(lpMacroList) - nActivates;
	iCount *= nRepeat;
	Setup.iTotal = iCount;
	Setup.idDialog = IDD_MACRO_STATUS;
	Setup.lpFileName = NULL;
    hDlg = AstralDlgParam( YES, PictPubApp.GetResourceHandle(), hParent, IDD_MACRO_STATUS,
						DlgMacroStatusProc,
						(LPARAM)(LPVOID)&Setup );
	if (hDlg)
		{
		if (lpMacroName)
			{
			STRING szString;

			GetWindowText(hDlg, szString, sizeof(szString));
			lstrcat(szString, _T(" - "));
			lstrcat(szString, lpMacroName);
			SetWindowText(hDlg, szString);
			}

		UpdateWindow(hDlg);
		}
	}

// Repeat macro nRepeat number of times
fError = FALSE;
while (--nRepeat >= 0 && !fError)
	{
	if (lpAbortProc && (*lpAbortProc)())
		break;
	// back to beginning of macro file
	lpNextPkt = (LPCMDPKT)ListGetHead(lpMacroList);

	// initialize sequencing
	fSequence = fSequenceAll;

	while (!fError && lpNextPkt)
		{
		if (lpAbortProc && (*lpAbortProc)())
			{
			fError = TRUE;
			break;
			}
		// get the packet to work on
		if (fCopyPackets)
			{
			lpCmdPkt = CopyPacket(lpNextPkt);
			if (!lpCmdPkt)
				{
				fError = TRUE;
				break;
				}
			}
		else
			{
			ListUnlink(lpMacroList, lpNextPkt);
			lpCmdPkt = lpNextPkt;
			}

		// get command id and parms for this command
		idCommand = lpCmdPkt->idCommand;

		// Find out whether this command requires sequencing
		// set it here, so command can change it if needed before
		// we actually set fSequence
		fCmdSequence = GetCommandSequence(idCommand);
		CommandType = GetCommandType(idCommand);

		// Handle the different types of commands
		switch (CommandType)
			{
			case CT_LOAD:
				// create new command list for load
				lpNewList = CreateCommandList();
				if (lpNewList)
					{
					ListAddTail(&lpNewList->PacketList, lpCmdPkt);

					// if we already have a command list containing commands,
					// kick off the execution of those commands before we
					// switch to the new command list
					if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList))
						{
						PlaybackCommands(lpCmdList);
						// if some command in the command list affects
						// sequencing force the whole command list to
						// be processed
						if (fSequence)
							{
							FlushCommands(lpCmdList);
							fSequence = fSequenceAll;
							}
						}
					// setup new command list for us to work with
					lpCmdList = lpNewList;
					lpCmdList->PhotoCDResOverride = PhotoCDResOverride;

					// If there are any activates in this macro make sure a
					// command that creates an image processes immediately
					if (nActivates)
						{
						PlaybackCommands(lpCmdList);
						FlushCommands(lpCmdList);
						fSequence = fSequenceAll;
						fCmdSequence = NO; // already sequenced
						}
					}
				break;

			case CT_COPY:
				// Make sure we have a command list to work with
				if (!lpCmdList)
					{
				 	Message(IDS_NOIMAGETOWORKON);
					fError = TRUE;
					break;
					}
				// Just add this command to the command list
				ListAddTail(&lpCmdList->PacketList, lpCmdPkt);

				// If there are any activates in this macro make sure a
				// command that creates an image processes immediately
				if (nActivates)
					{
					PlaybackCommands(lpCmdList);
					FlushCommands(lpCmdList);
					fSequence = fSequenceAll;
					fCmdSequence = NO; // already sequenced
					}
				break;

			case CT_SAVE:
			case CT_EDIT:
			case CT_MASK:
			case CT_MODE:
			case CT_EDITUNDO:
			case CT_MASKUNDO:
			case CT_EDITOBJ:
			case CT_CLOSE:
				// Make sure we have a command list to work with
				if (!lpCmdList)
					{
				 	Message(IDS_NOIMAGETOWORKON);
					fError = TRUE;
					break;
					}
				if (CommandType == CT_SAVE)
					{
					PlaybackCommands(lpCmdList);
					if (!lpCmdList->ThreadData.lpImage)
						{
				 		Message(IDS_NOIMAGETOWORKON);
						fError = TRUE;
						break;
						}
					}

				// Just add this command to the command list
				ListAddTail(&lpCmdList->PacketList, lpCmdPkt);
				if (CommandType != CT_CLOSE)
					break;

			case CT_ACTIVATE:
				// Program or commands that affect window activation
				// are processed here
				switch (idCommand)
					{
					case IDS_CMD_CLOSE:
					case IDS_CMD_ACTIVATEWINDOW:
						{
						// if we already have a command list containing commands,
						// kick of the execution of those commands before we
						// switch to the new command list
						if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList))
							{
							PlaybackCommands(lpCmdList);
							// if some command in the command list affects
							// sequencing force the whole command list to
							// be processed
							if (fSequence)
								{
								FlushCommands(lpCmdList);
								fSequence = fSequenceAll;
								}
							}
						// if this was a close command, then wack the command list pointer
						if (idCommand == IDS_CMD_CLOSE)
							lpCmdList = NULL;
						else
							{
							// now process the activate and get a new command list
							lpNewList = ProgActivateWindow(
									(LPACTIVATEWINDOW_PARMS)lpCmdPkt->lpParms);
							// setup the new command list if we got one
							if (lpNewList)
								lpCmdList = lpNewList;
							else
								{
								CommandError(idCommand);
								fError = TRUE;
								}
							// activate don't go through command processing
							// so we have to free it up here
							FreeUpPacket(lpCmdPkt);
							}
						}
					break;

					default:
					break;
					}
				break;

			default:
				break;
			}
		// if command just handled requires sequencing
		// set sequencing flag
		if (fCmdSequence)
			fSequence = YES;
		if (fCopyPackets)
			// get next command packet in macro list
			lpNextPkt = (LPCMDPKT)ListGetNext(lpNextPkt);
		else
			// head of list will be next one if we're not copying
			lpNextPkt = (LPCMDPKT)ListGetHead(lpMacroList);
		}
	}
// get rid of macro list
DestroyPacketList(lpMacroList);

// if we already have a command list containing commands,
// kick off the execution of those commands
if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList))
	{
	PlaybackCommands(lpCmdList);
	if (fSequenceAll)
		FlushCommands(lpCmdList);
	}

// turn off the macro mode
EnableWindow(hParent, TRUE);
if ( AstralStrEx( IDS_APPNAME, szAppName, sizeof(szAppName) ) )
	SetWindowText( PictPubApp.Get_hWndAstral(), szAppName );
// if we have a progress dialog, nuke it
if (hDlg)
	AstralDlgEnd(hDlg, TRUE);
// if we are display the macro status for another modal dialog 
// make sure the main app stuff is still disabled
if (hParent != PictPubApp.Get_hWndAstral())
	{
	EnableOverlappedWindow( PictPubApp.Get_hWndAstral(), FALSE );
	EnableWindow(PictPubApp.Get_hWndAstral(), FALSE);
	}
MacroMode = MM_NONE;
return(TRUE);
}
示例#8
0
/**
 * Removes and frees an element in a list by comparing the content.
 * A callback function is used to define the method of comparison for each element
 * @param aList the list in which the search is to be conducted
 * @param content pointer to the content to look for
 * @param callback pointer to a function which compares each element
 * @return 1=item removed, 0=item not removed
 */
int ListRemoveItem(List* aList, void* content, int(*callback)(void*, void*))
{ /* remove from list and free the content */
	return ListUnlink(aList, content, callback, 1);
}
示例#9
0
/**
 * Removes but does not free an element in a list by comparing the content.
 * A callback function is used to define the method of comparison for each element.
 * @param aList the list in which the search is to be conducted
 * @param content pointer to the content to look for
 * @param callback pointer to a function which compares each element
 * @return 1=item removed, 0=item not removed
 */
int ListDetachItem(List* aList, void* content, int(*callback)(void*, void*))
{ /* do not free the content */
	return ListUnlink(aList, content, callback, 0);
}
示例#10
0
/**
 * Removes and frees an item in a list by comparing the pointer to the content.
 * @param aList the list from which the item is to be removed
 * @param content pointer to the content to look for
 * @return 1=item removed, 0=item not removed
 */
int ListRemove(List* aList, void* content)
{
	return ListUnlink(aList, content, NULL, 1);
}
示例#11
0
/**
 * Removes but does not free an item in a list by comparing the pointer to the content.
 * @param aList the list in which the search is to be conducted
 * @param content pointer to the content to look for
 * @return 1=item removed, 0=item not removed
 */
int ListDetach(List* aList, void* content)
{
	return ListUnlink(aList, content, NULL, 0);
}