Beispiel #1
0
void
mapRelease(struct map *m)
{
	if (m) {
		memoryFree(m->buffer);
		memoryFree(m);
	}
}
int mpeg3_delete_title(mpeg3_title_t *title)
{
	mpeg3_delete_fs(title->fs);
	if(title->timecode_table_size)
	{
		memoryFree(title->timecode_table);
	}
	memoryFree(title);
	return 0;
}
Beispiel #3
0
void tcpConnectionListenerRunThread(TcpConnection tcpConnection){
	TcpConnectionInternal* internal=(TcpConnectionInternal*)tcpConnection;
	//Declaring proc    ess variables.
	int size ;
	void* buffer;
        void *commandBuffer;
	int commandSize;
	int currentSize;
	int tempSize=0;
        int result;
	while(internal->active==TRUE){
                size=0;
                while(size<SIZE_OF_INT){
                        tempSize=read(internal->sockfd,&commandSize+size, SIZE_OF_INT-size);
                        if(tempSize<=0){
                                internal->active=FALSE;
                                      distributionManagerHandleTcpConnectionListenerFailure(internal->distributionManager,internal,internal->coreManagerId);
                                return;
                        }
                        size +=tempSize;
                }
                commandSize=htonl(commandSize);
                buffer=memoryAlloc(commandSize-SIZE_OF_INT);
                currentSize=0;
                while(currentSize<commandSize-SIZE_OF_INT){
                        currentSize+=read(internal->sockfd,buffer+currentSize, MIN(MAX_TCP_MESSAGE_SIZE,commandSize-currentSize-SIZE_OF_INT));
                        if(currentSize<=0){
                                internal->active=FALSE;
                                distributionManagerHandleTcpConnectionListenerFailure(internal->distributionManager,internal,internal->coreManagerId);
                                memoryFree(buffer);
                                return;
                        }
                }
                Command command=commandDeSerialize(buffer,commandSize-SIZE_OF_INT);
                commandPush(command,IP,STRING,internal->remoteIp,internal->remoteIpLenght);
                commandPush(command,PORT,INTEGER,&internal->remotePort);
                memoryFree(buffer);
                // handle message
                distributionManagerConsumeTcp(internal->distributionManager,command);
                // Create the result message and send it to client
                commandSize=commandSerialize(command,&commandBuffer);
                result=writeToSocket(internal->sockfd,commandBuffer,commandSize);
                memoryFree(commandBuffer);
                if(result<0){
                        internal->active=FALSE;
                        distributionManagerHandleTcpConnectionListenerFailure(internal->distributionManager,internal,internal->coreManagerId);
                        return;
                }
                // Delete all none model or none atomic commands
                if(commandIsDeleteOnExit(command)==TRUE){
                    commandFree(command);
                }
	}
        internal->readyForCleanup+=LISTENER_READY_FOR_CLEANUP;
}
Beispiel #4
0
void attributeFree(Attribute attribute,int deleteData){
    if(deleteData==TRUE){
        if(attribute->nameLength>0){
            memoryFree(attribute->name);
        }
        if(attribute->dataLength>0){
            memoryFree(attribute->data);
        }
    }
    memoryFree(attribute);
}
Beispiel #5
0
/*
 * serialize Node;
 */
int nodeSerialize( Node node,char ** result){

        NodeInternal* internal=(NodeInternal*)node;
        Array attributes;
        stringHashmapToArray(node->attributes,&attributes);
        void* attributeBuffer;
        int attributeLength;
	int size=SIZE_OF_INT*4;
	int numberOfAttributes=arrayGetLength(attributes);
        int i;
        Attribute attribute;
        for(i=0;i<numberOfAttributes;i++){
            attribute=arrayGetObject(attributes,i);
            size+=attributeSerializeLocal(attribute,&attributeBuffer);
            memoryFree(attributeBuffer);
        }
        stringHashmapIterate(internal->children,registryUpdateNodeBufferSize,(Object)&size);
	
	char * buffer=memoryAlloc(size);
        *result=buffer;
       	memcpy(buffer+SIZE_OF_INT*0,&(internal->schemaId),SIZE_OF_INT);
        memcpy(buffer+SIZE_OF_INT*1,&(internal->id),SIZE_OF_INT);
        memcpy(buffer+SIZE_OF_INT*2,&numberOfAttributes,SIZE_OF_INT);
        buffer+=SIZE_OF_INT*3;
        for(i=0;i<numberOfAttributes;i++){
            attribute=arrayGetObject(attributes,i);
            attributeLength=attributeSerializeLocal(attribute,&attributeBuffer);
            memcpy(buffer,attributeBuffer,attributeLength);
            buffer+=attributeLength;
            memoryFree(attributeBuffer);
        }
        arrayFree(attributes);
        ArrayList list=arrayListCreate();
        stringHashmapIterate(internal->children,registryCreateChildrenBufferElemrnts,list);
	int numberOfChildren=arrayListSize(list);
	memcpy(buffer,&numberOfChildren,SIZE_OF_INT);
        buffer+=SIZE_OF_INT;
	int j;
        for(j=0;j<numberOfChildren;j++){
            void* bufferElement=arrayListGetValueAt(list,j);
            int bufferSize;
            memcpy(&bufferSize,bufferElement+SIZE_OF_INT,SIZE_OF_INT);
            memcpy(buffer,bufferElement,SIZE_OF_INT*2+bufferSize);
            buffer+=SIZE_OF_INT*2+bufferSize;
            memoryFree(bufferElement);
	}
        arrayListFree(list);
	return size;
}
Beispiel #6
0
void tcpConnectionFree(TcpConnection tcpConnection,int killThread){
	TcpConnectionInternal* internal=(TcpConnectionInternal*)tcpConnection;
        if(killThread==TRUE){
                environmentThreadFree(internal->thread);
        }
        memoryFree(tcpConnection);
}
Beispiel #7
0
void *memoryRealloc(void *buffer, size_t size, const char *file, unsigned line)
{
	if (size > 0) {
		void *realloced;

		if ((realloced = (realloc)(buffer, size)) != NULL) {
			if (memory != NULL) {
				memoryRemove(buffer);
				memorySet(realloced, size);
			}

			return realloced;
		}

		printf("%s:%u: warning: failed to reallocate memory buffer\n", file, line);
	}

	/**
	 * Don't need to check if Memory set because
	 * we may want to use default free function.
	 */
	memoryFree(buffer, file, line);

	return NULL;
}
Beispiel #8
0
static struct node *
expand_search(struct map *m,struct key *key)
{	
	int i;
	int s=m->size;
	struct node *old=m->buffer;

	struct node *buffer=(struct node*)memoryAlloc(m->size*2*sizeof(struct node));
	if (buffer==0) {
		return 0;
	}

	m->size*=2;
	m->freenode=0;
	m->buffer=buffer;
	init_table(m);

	for (i=0;i<s;i++) {
		if (old[i].value!=0) {
			map_search(m,old[i].key)->value = old[i].value;
		}
	}

	memoryFree(old);

	return map_search(m,key);
}
int mpeg3_delete_vtrack(mpeg3_t *file, mpeg3_vtrack_t *vtrack)
{
	if(vtrack->video)
		mpeg3video_delete(vtrack->video);
	if(vtrack->demuxer)
		mpeg3_delete_demuxer(vtrack->demuxer);
	memoryFree(vtrack);
}
Beispiel #10
0
int tcpConnectionSend(TcpConnection tcpConnection,Command command){
    TcpConnectionInternal* internal=(TcpConnectionInternal*)tcpConnection;
    int size ;
    void* buffer;
    void *commandBuffer;
    int commandSize;
    int currentSize;
    int tempSize=0;
    int result;
    if(internal->active==FALSE){
        return;
    }
    commandSize=commandSerialize(command,&commandBuffer);
    result = tcpConnectionWriteToSocket(internal->sockfd,commandBuffer,commandSize);
    memoryFree(commandBuffer);
    if(result!=0){
        
    }
    size=0;
    while(size<SIZE_OF_INT){
            tempSize=read(internal->sockfd,&commandSize+size, SIZE_OF_INT-size);
            if(tempSize<0){
                    internal->active=FALSE;
                    distributionManagerHandleTcpConnectionListenerFailure(internal->distributionManager,internal,internal->coreManagerId);
                    return;
            }
            size +=tempSize;
    }
    commandSize=htonl(commandSize);
    buffer=memoryAlloc(commandSize-SIZE_OF_INT);
    currentSize=0;
    while(currentSize<commandSize-SIZE_OF_INT){
            currentSize+=read(internal->sockfd,buffer+currentSize, MIN(MAX_TCP_MESSAGE_SIZE,commandSize-currentSize-SIZE_OF_INT));
            if(currentSize<0){
                    internal->active=FALSE;
                    distributionManagerHandleTcpConnectionListenerFailure(internal->distributionManager,internal,internal->coreManagerId);
                    memoryFree(buffer);
                    return;
            }
    }
    Command resultCommand=commandDeSerialize(buffer,commandSize-SIZE_OF_INT);
    commandFill(resultCommand,command);
    return VALID;
}
Beispiel #11
0
int tcpConnectionSend(TcpConnection tcpConnection,Command command){
    TcpConnectionInternal* internal=(TcpConnectionInternal*)tcpConnection;
    if(internal->active==FALSE){
        return;
    }
    void *commandBuffer;
    int commandSize=commandSerialize(command,&commandBuffer);
    int result = writeToSocket(internal->sockfd,commandBuffer,commandSize);
    memoryFree(commandBuffer);
    return result;
}
Beispiel #12
0
void commandContainerCleanup(CommandContainer commandContainer){
	CommandContainerInternal* internal=(CommandContainerInternal*)commandContainer;
        lockLock(internal->lock);
        time_t currentTime;       // Stores seconds elapsed since 01-01-1970
        time(&currentTime);
        // Cleanup atomic commands
        if(linkedListSize(internal->atomicCommands)>0){
            int length=linkedListSize(internal->atomicCommands);
            Command atomicCommand;
            while(length>0){
                 linkedListGetFirst(internal->atomicCommands,(Object*)&atomicCommand);
                 int commandTime=commandGetInt(atomicCommand,SERVER_HANDLING_TIME);
                 int distributed=commandGetInt(atomicCommand,DISTRIBUTED);
                 if((currentTime-commandTime>MAX_TIME_TO_HOLD_COMMAND&&distributed==TRUE)||(currentTime-commandTime>MAX_TIME_TO_HOLD_UNCLEANED_COMMAND)){
                   commandFree(atomicCommand);
                   linkedListRemoveFirst(internal->atomicCommands);
                 }else{
                     break;
                 }
                 length=linkedListSize(internal->atomicCommands);
            }
        }
        
        // Cleanup commands
        int length=linkedListSize(internal->versions);
        int i;
        int* intBuffer;
        while(length>0){
            linkedListGetFirst(internal->versions,(Object*)&intBuffer);
            Command temp;
            hashmapGet(internal->versionMap,*intBuffer,(Object*)&temp);
            int commandTime=commandGetInt(temp,SERVER_HANDLING_TIME);            
            int persisted=commandGetInt(temp,PERSISTED);
            int distributed=commandGetInt(temp,DISTRIBUTED);
            if((currentTime-commandTime>MAX_TIME_TO_HOLD_COMMAND&&persisted==TRUE&&distributed==TRUE)||(currentTime-commandTime>MAX_TIME_TO_HOLD_UNCLEANED_COMMAND)){
                linkedListRemoveFirst(internal->versions);
                hashmapRemove(internal->versionMap,*intBuffer);
                memoryFree(intBuffer);
                commandFree(temp);
            }else{
                break;
            }
            length=linkedListSize(internal->versions);
        }
        lockUnlock(internal->lock);
        
        

}
Beispiel #13
0
int updateChildren(Registry registry, Array array, int parentId) {
    Node parent;
    Node child;
    registryGetNode(registry, parentId, &parent);
    int size = arrayGetLength(array);
    int i;
    for (i = 0; i < size; i++) {
        int childId;
        int keyLength;
        void *bufferElement = arrayGetObject(array, i);
        memcpy(&childId, bufferElement, SIZE_OF_INT);
        memcpy(&keyLength, bufferElement + SIZE_OF_INT, SIZE_OF_INT);
        registryGetNode(registry, childId, &child);
        registryAddChild(registry, parent, child, bufferElement + SIZE_OF_INT * 2, keyLength);
        memoryFree(bufferElement);
    }
    arrayFree(array);
    return VALID;
}
static void rf_thread_loop(const void *arg)
{
    SL_DEBUG_PRINT("rf_thread_loop: starting (id: %d)\n", rf_thread_id);
    for (;;) {
        osEvent event = osSignalWait(0, osWaitForever);

        if (event.status != osEventSignal) {
            continue;
        }

        platform_enter_critical();

        if (event.value.signals & SL_RX_DONE) {
            while(rx_queue_tail != rx_queue_head) {
                void* handle = (void*) rx_queue[rx_queue_tail];
                RAIL_RxPacketInfo_t* info = (RAIL_RxPacketInfo_t*) memoryPtrFromHandle(handle);
                device_driver.phy_rx_cb(
                        info->dataPtr + 1,
                        info->dataLength - 1, 
                        info->appendedInfo.lqi, 
                        info->appendedInfo.rssiLatch, 
                        rf_radio_driver_id);

                memoryFree(handle);
                rx_queue[rx_queue_tail] = NULL;
                rx_queue_tail = (rx_queue_tail + 1) % RF_QUEUE_SIZE;
            }

        } else if (event.value.signals & SL_TX_DONE) {
            device_driver.phy_tx_done_cb(rf_radio_driver_id,
                    current_tx_handle,
                    PHY_LINK_TX_SUCCESS,
                    1,
                    1);
        } else if (event.value.signals & SL_ACK_RECV) {
            device_driver.phy_tx_done_cb( rf_radio_driver_id,
                    current_tx_handle,
                    (event.value.signals & SL_ACK_PEND) ? PHY_LINK_TX_DONE_PENDING : PHY_LINK_TX_DONE,
                    1,
                    1);
        } else if (event.value.signals & SL_ACK_TIMEOUT) {
            waiting_for_ack = false;
            device_driver.phy_tx_done_cb(rf_radio_driver_id,
                    current_tx_handle,
                    PHY_LINK_TX_FAIL,
                    1,
                    1);
        } else if(event.value.signals & SL_TX_ERR) {
            device_driver.phy_tx_done_cb( rf_radio_driver_id,
                    current_tx_handle,
                    PHY_LINK_CCA_FAIL,
                    8,
                    1);
        } else if(event.value.signals & SL_CAL_REQ) {
            SL_DEBUG_PRINT("rf_thread_loop: SL_CAL_REQ signal received (unhandled)\n");
        } else if(event.value.signals & SL_RXFIFO_ERR) {
            SL_DEBUG_PRINT("rf_thread_loop: SL_RXFIFO_ERR signal received (unhandled)\n");
        } else if(event.value.signals & SL_TXFIFO_ERR) {
            SL_DEBUG_PRINT("rf_thread_loop: SL_TXFIFO_ERR signal received (unhandled)\n");
        } else if(event.value.signals & SL_QUEUE_FULL) {
            SL_DEBUG_PRINT("rf_thread_loop: SL_QUEUE_FULL signal received (packet dropped)\n");
        } else {
            SL_DEBUG_PRINT("rf_thread_loop unhandled event status: %d value: %d\n", event.status, event.value.signals);
        }

        platform_exit_critical();
    }
}
Beispiel #15
0
void arcFree(Arc arc){
    memoryFree(arc->arcName);
    memoryFree(arc);
}
Beispiel #16
0
/*
 * connectionListenerRunThread
 * 1. Listen and wait for connections request
 * 2. convert the request into command
 * 3. pass the request command to the DistributionMAnager
 */
void connectionListenerRunThread(ConnectionListener connectionListener) {

    // Declaring process variables.
    ConnectionListenerInternal* internal=(ConnectionListenerInternal*)connectionListener;
    int server_sockfd, client_sockfd;
    int server_len ;
    int size ;
    unsigned client_len;
    struct sockaddr_in server_address;
    struct sockaddr_in client_address;
    void* readBuffer;
    void* writeBuffer;
    int commandSize;
    int currentSize;
    const int       optVal = 1;
    const socklen_t optLen = sizeof(optVal);
    // Remove any old socket and create an unnamed socket for the server.
    server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
    int rtn = setsockopt(server_sockfd, SOL_SOCKET, SO_REUSEADDR, (void*) &optVal, optLen);
    server_address.sin_family = AF_INET;
    server_address.sin_addr.s_addr = INADDR_ANY;// htons(ipConverterToLong(internal->ip));
    server_address.sin_port = htons(internal->port);
    server_len = sizeof(server_address);

    int rc = bind(server_sockfd, (struct sockaddr *) &server_address, server_len);
    if(rc<0) {
        Throw (Fatal,1,"Failt to bind to listen port \n");
    }
    printf("RC from bind = %d\n", rc );

    //Create a connection queue and wait for clients
    rc = listen(server_sockfd, 5);
    printf("RC from listen = %d\n", rc ) ;

    client_len = sizeof(client_address);
    while(internal->active==TRUE) {
        client_sockfd = accept(server_sockfd, (struct sockaddr *) &client_address, &client_len);
        char* ip=inet_ntoa(client_address.sin_addr);
        size=0;
        size += read(client_sockfd,&commandSize+size, SIZE_OF_INT);
        if(size<SIZE_OF_INT) {
            continue;
        }
        commandSize=htonl(commandSize);
        readBuffer=memoryAlloc(commandSize-SIZE_OF_INT);
        currentSize=0;
        currentSize+=read(client_sockfd,readBuffer+currentSize, commandSize-SIZE_OF_INT);
        if(currentSize<commandSize-SIZE_OF_INT) {
            memoryFree(readBuffer);
            continue;
        }
        Command command=commandDeSerialize(readBuffer,commandSize-SIZE_OF_INT);
        memoryFree(readBuffer);
        // handle message
        handleMessage(client_sockfd,internal,command,ip);
        // Create the result message and send it to client
        commandSize=commandSerialize(command,&writeBuffer);
        int result = write(client_sockfd,writeBuffer,commandSize);
        if(result<0) {
            printf("ConnectionListener Fail to write to socket");
        }
        memoryFree(writeBuffer);
        //commandDestroy(command);
    }
    printf("Server connection listener stoped\n");
    close(client_sockfd);

}
Beispiel #17
0
void lockFree(Lock lock){
    LockInternal* internal=(LockInternal*)lock;
    pthread_mutex_destroy(&internal->mutex);
    memoryFree(lock);
}
Beispiel #18
0
void fileHelperLoad(FileHelper fileHelper) {
    FileHelperInternal *m = (FileHelperInternal *) fileHelper;
    fileHelperCheckCreate(m->filePath);
    int sizeOfInt = sizeof(int);
    struct direct **schemasIds = {0};
    struct direct *schenaId;
    int size = scandir(m->filePath, &schemasIds, 0, alphasort);
    // loop all schemas
    int i;
    for (i = 0; i < size; i++) {
        schenaId = (struct direct *) schemasIds[i];
        char *schemaIdString = schenaId->d_name;
        int schemaId = atoi(schemaIdString);
        if (schemaId != 0) {
            printf("schema %s\n", schenaId->d_name);
            struct direct **pagesIds = {0};
            struct direct *pageStruct;
            char endOdString = '\0';
            int pageDirLength = strlen(m->filePath);
            int schemaIdStringLength = strlen(schemaIdString);
            char slesh = '/';
            char *pageDir = (char *) memoryAlloc(pageDirLength + 1 + schemaIdStringLength + 1);
            memcpy(pageDir, m->filePath, pageDirLength);
            memcpy(pageDir + pageDirLength, &slesh, 1);
            memcpy(pageDir + pageDirLength + 1, schemaIdString, schemaIdStringLength);
            memcpy(pageDir + pageDirLength + 1 + schemaIdStringLength, &endOdString, 1);


//			cleanBuffer(pageDir);
//			strcat(pageDir,m->filePath);
//			strcat(pageDir,"/");
//			strcat(pageDir,schemaIdString);
            HashMap childrenRelations = hashmapCreate(SMALL_CONTAINER_SIZE);
            Registry registry = registryCreate();
            hashmapPut(m->registryMap, schemaId, registry);
            PageManager pageManager = pageManagerCreate(schemaId, pageDir);
            hashmapPut(m->managers, schemaId, pageManager);
            int size = scandir(pageDir, &pagesIds, 0, alphasort);
            int h;
            //loop pages
            for (h = 0; h < size; h++) {
                //scandir (pageDir, &pagesIds, 0, alphasort);
                pageStruct = (struct direct *) pagesIds[h];
                char *pageString = pageStruct->d_name;
                int pageId = atoi(pageString);
                if (pageId != 0) {
                    printf("page %s\n", pageStruct->d_name);
                    // create file path.

                    //int i=0;
                    int pageDirLength = strlen(pageDir);
                    int pageStringLength = strlen(pageString);
                    char slesh = '/';
                    char *filePath = (char *) memoryAlloc(pageDirLength + 1 + pageStringLength + 1);
                    memcpy(filePath, pageDir, pageDirLength);
                    memcpy(filePath + pageDirLength, &slesh, 1);
                    memcpy(filePath + pageDirLength + 1, pageString, pageStringLength);
                    memcpy(filePath + pageDirLength + 1 + pageStringLength, &endOdString, 1);
                    FILE *fp;
                    long len;
                    // Create pointer to file.
                    fp = fopen(filePath, "rb");
                    if (fp == NULL) {
                        printf("couldn't open the properties file");
                    }
                    fseek(fp, 0, SEEK_END);                // Go to end
                    len = ftell(fp);                        // Get position at end (length)
                    // Read data to buffer
                    char *buffer = memoryAlloc(sizeof(char) * len); // Create buffer
                    char *pointerToFreeBuffer = buffer;
                    fseek(fp, 0, SEEK_SET);                // Go to the beginning.
                    int result = fread(buffer, len, 1, fp);                // Read into buffer
                    if (result < 0) {
                        printf("Fail to read file : %s", buffer);
                    }
                    fclose(fp);
                    int order = 0;
                    long index = 0;
                    long step = 0;
                    while (index < len) {
                        char *start = buffer;
                        int id;
                        int schemaId;
                        int numberOfAttributes;
                        int childrenSize;
                        int attributeSize;
                        memcpy(&schemaId, buffer + SIZE_OF_INT * 0, SIZE_OF_INT);
                        memcpy(&id, buffer + SIZE_OF_INT * 1, SIZE_OF_INT);
                        memcpy(&numberOfAttributes, buffer + SIZE_OF_INT * 2, SIZE_OF_INT);
                        buffer += SIZE_OF_INT * 3;
                        Node node;
                        nodeCreate(registry, id, schemaId, FALSE, &node);
                        int h;
                        for (h = 0; h < numberOfAttributes; h++) {
                            memcpy(&attributeSize, buffer, SIZE_OF_INT);
                            Attribute attribute = attributeDeserializeLocal(buffer);
                            buffer += attributeSize;
                            stringHashmapPut(node->attributes, attribute->name, attribute->nameLength, attribute);
                        }
                        memcpy(&childrenSize, buffer, SIZE_OF_INT);
                        Array children = arrayCreate(childrenSize);
                        hashmapPut(childrenRelations, id, children);
                        int i;
                        buffer += SIZE_OF_INT;
                        int childrenIdBuffer;
                        for (i = 0; i < childrenSize; i++) {
                            memcpy(&childrenIdBuffer, buffer + SIZE_OF_INT, SIZE_OF_INT);
                            void *bufferElement = memoryAlloc(childrenIdBuffer + SIZE_OF_INT * 2);
                            memcpy(bufferElement, buffer, SIZE_OF_INT * 2 + childrenIdBuffer);
                            arrayInsertObject(children, bufferElement);
                            buffer += SIZE_OF_INT * 2 + childrenIdBuffer;
                        }
                        step = buffer - start;
                        index += step;
                        pageManagerRegister(pageManager, pageId, id, index - step, index, order, filePath);
                        order++;
                    }
                    // Free the file buffer
                    memoryFree(pointerToFreeBuffer);
                }
            }
            if (size > 0) {
                while (size) {
                    size = size - 1;
                    free(pagesIds[size]);
                }
                free(pagesIds);
            }
            hashmapIterate(childrenRelations, &updateChildren, registry);
            hashmapFree(childrenRelations);
        }
    }
    if (size > 0) {
        while (size) {
            size = size - 1;
            free(schemasIds[size]);
        }
        free(schemasIds);
    }

}
Beispiel #19
0
EXPORT(sqInt) primitiveMPEG3ReadFrameBufferOffset(void) {
	unsigned char *bufferBaseAddr;
	sqInt result;
	sqInt i;
	unsigned char  ** outputRowsPtr;
	mpeg3_t * file;
	sqInt fileHandle;
	usqInt *aBuffer;
	sqInt aBufferOffset;
	sqInt xNumber;
	sqInt yNumber;
	sqInt width;
	sqInt height;
	sqInt outWidth;
	sqInt outHeight;
	sqInt model;
	sqInt aNumber;
	sqInt aByteNumber;
	sqInt _return_value;

	fileHandle = interpreterProxy->stackValue(11);
	interpreterProxy->success(interpreterProxy->isWords(interpreterProxy->stackValue(10)));
	aBuffer = ((unsigned *) (interpreterProxy->firstIndexableField(interpreterProxy->stackValue(10))));
	aBufferOffset = interpreterProxy->stackIntegerValue(9);
	xNumber = interpreterProxy->stackIntegerValue(8);
	yNumber = interpreterProxy->stackIntegerValue(7);
	width = interpreterProxy->stackIntegerValue(6);
	height = interpreterProxy->stackIntegerValue(5);
	outWidth = interpreterProxy->stackIntegerValue(4);
	outHeight = interpreterProxy->stackIntegerValue(3);
	model = interpreterProxy->stackIntegerValue(2);
	aNumber = interpreterProxy->stackIntegerValue(1);
	aByteNumber = interpreterProxy->stackIntegerValue(0);
	if (interpreterProxy->failed()) {
		return null;
	}
	file = mpeg3tValueOf(fileHandle);
	if (file == null) {
		if (interpreterProxy->failed()) {
			return null;
		}
		interpreterProxy->popthenPush(13, 0);
		return null;
	}
	if (aNumber < 0) {
		interpreterProxy->success(0);
		return null;
	}
	if (aNumber >= (result = mpeg3_total_vstreams(file))) {
		interpreterProxy->success(0);
		if (interpreterProxy->failed()) {
			return null;
		}
		interpreterProxy->popthenPush(13, 0);
		return null;
	}
	bufferBaseAddr = ((unsigned char *) aBuffer);
	outputRowsPtr = (unsigned char **) memoryAllocate(1,sizeof(unsigned char*) * outHeight);
	for (i = 0; i <= (outHeight - 1); i += 1) {
		outputRowsPtr[i] = ((bufferBaseAddr + aBufferOffset) + (aByteNumber * i));
	}
	result = mpeg3_read_frame(file,outputRowsPtr,xNumber,yNumber,width,height,outWidth,outHeight,model,aNumber);
	memoryFree(outputRowsPtr);
	_return_value = interpreterProxy->integerObjectOf(result);
	if (interpreterProxy->failed()) {
		return null;
	}
	interpreterProxy->popthenPush(13, _return_value);
	return null;
}
Beispiel #20
0
int validationManagerValidateOnCoreExecuteInternalRecurcive(ValidationManager validationManager,ArrayList commands,int administrator,int dept){
    ValidationManagerStruct* internal=(ValidationManagerStruct*)validationManager;
                if(commands!=NULL&&dept<arrayListSize(commands)){
        Command command=arrayListGetValueAt(commands,dept);
        int coreManagerId=commandGetInt(command,CORE_MANAGER_ID);
	int sessionId=commandGetInt(command,SESSION_ID);
	int transaction=commandGetInt(command,TRANSACTION);
        int schimaId=commandGetInt(command,SCHEMA_ID);
        int type=commandGetInt(command,COMMAND_TYPE);
        int version=commandGetInt(command,VERSION);
        int entityId=commandGetInt(command,ENTITY_ID);
        
        VALIDATE_TRANSACTION(transaction);
	VALIDATE_CORE_MANAGER_ID(coreManagerId);
	VALIDATE_SESSION_ID(sessionId);
	if(IS_CREATE_NEW_ENTITY(type)){                
                int lock=commandGetInt(command,LOCK);
                StringHashMap newAttributesMap=commandGetAttributes(command,ATTRIBUTES);
                VALIDATE(registryValidateNodeCreate(internal->registry,entityId));
                Node node;
                nodeCreate(internal->registry,entityId,schimaId,lock,&node);
                stringHashmapPutAll(node->attributes,newAttributesMap);
                stringHashmapFree(newAttributesMap);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);
                if( VALID!= result){
                    registryDeleteNode(internal->registry,node);
                    return result;
                }
        char* buf;
        int length=nodeSerialize(node,&buf);
        commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length);
        memoryFree(buf);
	}
	if(IS_ADD_CHILD_ENTITY_TO_PARENT_ENTITY(type)){
                char* arcName;
		int childEntityId=commandGetInt(command,ENTITY_CHILD_ID);
                int arcNameLenght=commandGetString(command,ARC_NAME,&arcName);
                Node parent;
                registryGetNode(internal->registry,entityId,&parent);
                Node child;
                registryGetNode(internal->registry,childEntityId,&child);
                VALIDATE(registryValidateAddChild(parent,child,arcName,arcNameLenght,sessionId));
                registryAddChild(internal->registry,parent,child,arcName,arcNameLenght);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);
                if( VALID!= result){
                    registryRemoveChild(internal->registry,parent,arcName,arcNameLenght);
                    return result;
                }
                char* buf;
                int length=nodeSerialize(parent,&buf);
                commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length);
                memoryFree(buf);
	}
	if(IS_REMOVE_CHILD_ENTITY_FROM_PARENT_ENTITY(type)){
                char* arcName;
		int childEntityId=commandGetInt(command,ENTITY_CHILD_ID);
                int arcNameLenght=commandGetString(command,ARC_NAME,&arcName);
		Node parent;
                registryGetNode(internal->registry,entityId,&parent);
                Node child;
                registryGetNode(internal->registry,childEntityId,&child);
                VALIDATE(registryValidateRemoveChild(parent,arcName,arcNameLenght,sessionId));
                registryRemoveChild(internal->registry,parent,arcName,arcNameLenght);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);
                if( VALID!= result){
                    registryAddChild(internal->registry,parent,child,arcName,arcNameLenght);
                    return result;
                }
        char* buf;
        int length=nodeSerialize(parent,&buf);
        commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length);
        memoryFree(buf);
	}
	if(IS_LOCK_ENTITY(type)){
                int lock=commandGetInt(command,LOCK);
                int forceLock=commandGetInt(command,FORCE_LOCK);
                Node node;
                registryGetNode(internal->registry,entityId,&node);
		VALIDATE(registryValidateUpdateLock(node,lock,sessionId,forceLock,administrator));
                registryUpdateLock(internal->registry,node,lock,sessionId);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);
                if( VALID!= result){
                    int revertedLock=lock==TRUE?FALSE:TRUE;                    		
                    registryUpdateLock(internal->registry,node,revertedLock,sessionId);
                    return result;
                }
	}
        if(IS_DELETE_ENTITY(type)){
                int lock=commandGetInt(command,LOCK);
                Node node;
                VALIDATE(registryGetNode(internal->registry,entityId,&node));
		VALIDATE(registryValidateDeleteNode(node,sessionId));
		registryDeleteNode(internal->registry,node);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);
                if( VALID!= result){
                    nodeCreate(internal->registry,entityId,schimaId,lock,&node);                    
                    return result;
                }                
        }
        if(IS_ADD_ATTRIBUTE(type)){
                StringHashMap newAttributesMap=commandGetAttributes(command,ATTRIBUTES);
                Node node;
                registryGetNode(internal->registry,entityId,&node);
                VALIDATE(registryValidateUpdate(node,sessionId));
                Array array;
                stringHashmapToArray(newAttributesMap,&array);
                int lenght=arrayGetLength(array);
                int i;
                StringHashMap toRemove = stringHashmapCreate(SMALL_CONTAINER_SIZE);                
                for(i=0;i<lenght;i++){
                    Attribute newAttribute=(Attribute)arrayGetObject(array,i);
                    Attribute oldAttribute;
                    stringHashmapGet(node->attributes,newAttribute->name,newAttribute->nameLength,(Object) &oldAttribute);
                    if(oldAttribute!=NULL){
                        stringHashmapPut(toRemove,newAttribute->name,newAttribute->nameLength,oldAttribute);
                        stringHashmapRemove(node->attributes,newAttribute->name,newAttribute->nameLength);
                    }
                    stringHashmapPut(node->attributes,newAttribute->name,newAttribute->nameLength,(Object)newAttribute);
                }
                arrayFree(array);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);                
                if(result!=VALID){
                    stringHashmapToArray(newAttributesMap,&array);
                    lenght=arrayGetLength(array);                    
                    for(i=0;i<lenght;i++){
                        Attribute newAttribute=(Attribute)arrayGetObject(array,i);                       
                        stringHashmapRemove(node->attributes,newAttribute->name,newAttribute->nameLength);
                        attributeFree(newAttribute,TRUE);                  
                    }                 
                    stringHashmapPutAll(node->attributes,toRemove);  
                    arrayFree(array);
                    stringHashmapFree(toRemove);
                }else{
                    stringHashmapToArray(toRemove,&array);
                    lenght=arrayGetLength(array);
                    for(i=0;i<lenght;i++){
                        Attribute oldAttribute=(Attribute)arrayGetObject(array,i);
                        stringHashmapRemove(toRemove,oldAttribute->name,oldAttribute->nameLength);
                        attributeFree(oldAttribute,TRUE);                                           
                    }
                    arrayFree(array);
                    stringHashmapFree(toRemove);                    
                }
                stringHashmapFree(newAttributesMap);     
                char* buf;
                int length=nodeSerialize(node,&buf);
                commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length);
                memoryFree(buf);
        }
        if(IS_REMOVE_ATTRIBUTE(type)){
                StringHashMap toRemoveAttributeMap=commandGetAttributes(command,ATTRIBUTES);
                Node node;
                registryGetNode(internal->registry,entityId,&node);
                VALIDATE(registryValidateUpdate(node,sessionId));
                Array array;
                stringHashmapToArray(toRemoveAttributeMap,&array);
                int lenght=arrayGetLength(array);
                int i;
                StringHashMap oldAttributes = stringHashmapCreate(SMALL_CONTAINER_SIZE);
                for(i=0;i<lenght;i++){
                    Attribute toRemoveAttribute=(Attribute)arrayGetObject(array,i);
                    Attribute oldAttribute;
                    stringHashmapGet(node->attributes,toRemoveAttribute->name,toRemoveAttribute->nameLength,(Object) &oldAttribute);
                    if(oldAttribute!=NULL){
                        stringHashmapPut(oldAttributes,toRemoveAttribute->name,toRemoveAttribute->nameLength,(Object)oldAttribute);
                        stringHashmapRemove(node->attributes,toRemoveAttribute->name,toRemoveAttribute->nameLength);
                    }                    
                }   
                 arrayFree(array);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);                
                if(result!=VALID){
                    stringHashmapToArray(oldAttributes,&array);
                    lenght=arrayGetLength(array);                    
                    for(i=0;i<lenght;i++){
                        Attribute oldAttribute=(Attribute)arrayGetObject(array,i);                       
                        stringHashmapPut(node->attributes,oldAttribute->name,oldAttribute->nameLength,(Object)oldAttribute);            
                    }    
                     arrayFree(array);
                    stringHashmapToArray(toRemoveAttributeMap,&array);
                    lenght=arrayGetLength(array);                    
                    for(i=0;i<lenght;i++){
                        Attribute toRemoveAttribute=(Attribute)arrayGetObject(array,i);                       
                        stringHashmapPut(toRemoveAttributeMap,toRemoveAttribute->name,toRemoveAttribute->nameLength,(Object)toRemoveAttribute);            
                        attributeFree(toRemoveAttribute,TRUE);                        
                    }
                     arrayFree(array);
                    stringHashmapFree(toRemoveAttributeMap);                    
                }else{
                    stringHashmapToArray(oldAttributes,&array);
                    lenght=arrayGetLength(array);                    
                    for(i=0;i<lenght;i++){
                        Attribute oldAttribute=(Attribute)arrayGetObject(array,i);                       
                        stringHashmapRemove(oldAttributes,oldAttribute->name,oldAttribute->nameLength);            
                        attributeFree(oldAttribute,TRUE);                        
                    }   
                     arrayFree(array);
                    stringHashmapToArray(toRemoveAttributeMap,&array);
                    lenght=arrayGetLength(array);
                    for(i=0;i<lenght;i++){
                        Attribute toAddAttribute=(Attribute)arrayGetObject(array,i);                       
                        stringHashmapPut(toRemoveAttributeMap,toAddAttribute->name,toAddAttribute->nameLength,(Object)toAddAttribute);            
                        attributeFree(toAddAttribute,TRUE);                        
                    }
                     arrayFree(array);
                    stringHashmapFree(toRemoveAttributeMap);                    
                }        
        char* buf;
        int length=nodeSerialize(node,&buf);
        commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length);
        memoryFree(buf);
        }
        if(IS_UPDATE_ENTITY(type)){
                StringHashMap newAttributesMap=commandGetAttributes(command,ATTRIBUTES);
                Node node;
                registryGetNode(internal->registry,entityId,&node);
                StringHashMap oldAttributesMap=stringHashmapCreate(SMALL_CONTAINER_SIZE);                
                stringHashmapPutAll(oldAttributesMap,node->attributes);
                Array array;
                stringHashmapToArray(node->attributes,&array);
                int lenght=arrayGetLength(array);
                int i;                
                for(i=0;i<lenght;i++){
                    Attribute toRemoveAttribute=(Attribute)arrayGetObject(array,i);                                        
                    stringHashmapRemove(node->attributes,toRemoveAttribute->name,toRemoveAttribute->nameLength);                    
                }    
                stringHashmapPutAll(node->attributes,newAttributesMap);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);                
                if(result!=VALID){
                    stringHashmapToArray(node->attributes,&array);
                    lenght=arrayGetLength(array);
                    for(i=0;i<lenght;i++){
                        Attribute toRemoveAttribute=(Attribute)arrayGetObject(array,i);                                            
                        stringHashmapRemove(node->attributes,toRemoveAttribute->name,toRemoveAttribute->nameLength);                        
                        attributeFree(toRemoveAttribute,TRUE);
                    }
                    stringHashmapPutAll(node->attributes,oldAttributesMap);
                    stringHashmapFree(newAttributesMap);
                    stringHashmapFree(oldAttributesMap);
                }else{
                    stringHashmapToArray(oldAttributesMap,&array);
                    lenght=arrayGetLength(array);
                    for(i=0;i<lenght;i++){
                        Attribute oldAttribute=(Attribute)arrayGetObject(array,i);                       
                        stringHashmapRemove(oldAttributesMap,oldAttribute->name,oldAttribute->nameLength);            
                        attributeFree(oldAttribute,TRUE);                        
                    }                 
                    stringHashmapFree(oldAttributesMap);
                    stringHashmapFree(newAttributesMap);
                }
        char* buf;
        int length=nodeSerialize(node,&buf);
        commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length);
        memoryFree(buf);
        }
        
    }
    return VALID;
}
int main2()
{
	mpeg3_t *file;
	int i, result = 0;
	unsigned char *output, **output_rows;
	float *audio_output_f;
	short *audio_output_i;
	long 			total_samples = 0;
	Rect 			sourceRect;
	OSErr           error;
	PixMapHandle 	hPixmap;
    Ptr       		gBaseLocation;
	long			targetRowBytes;
	
	file = mpeg3_open("randomAlien.mpg");
	if(file)
	{

		mpeg3_set_cpus(file, 1);
  		//audio_output_f = (float *) memoryAllocate(1,BUFSIZE * sizeof(float)); 
		//audio_output_i = (short *) memoryAllocate(1,BUFSIZE * sizeof(short));
 		//mpeg3_set_sample(file, 11229518, 0); 
        //result = mpeg3_read_audio(file, audio_output_f, 0, 0, BUFSIZE, 0); 
    	// result = mpeg3_read_audio(file, 0, audio_output_i, 1, BUFSIZE, 0);
 		// fwrite(audio_output_i, BUFSIZE, 1, stdout);

  		//mpeg3_set_frame(file, 1000, 0);
  		
		sourceRect.top = 0;
		sourceRect.left = 0;
		sourceRect.bottom = mpeg3_video_height(file, 0);
		sourceRect.right = mpeg3_video_width(file, 0);

		error = NewGWorld (&gpGWOffScreen, 32, &sourceRect, NULL, NULL,  keepLocal);
		if (error != noErr)
			{
		    DebugStr ("\pUnable to allocate off screen image");
		 	}
	 
		hPixmap = GetGWorldPixMap (gpGWOffScreen);
		error = LockPixels (hPixmap);
		gBaseLocation = GetPixBaseAddr(hPixmap);
		targetRowBytes = ((**hPixmap).rowBytes & 0x3FFF)/4;

  		output_rows = (unsigned char **) memoryAllocate(1,sizeof(unsigned char*) * mpeg3_video_height(file, 0));
  		for(i = 0; i < mpeg3_video_height(file, 0); i++)
  			output_rows[i] = (unsigned char*) gBaseLocation + i * targetRowBytes*4;

		for (i=0;i < mpeg3_video_frames(file, 0);i++) {
			result = mpeg3_read_frame(file, 
 					output_rows, 
 					0, 
 					0, 
 					mpeg3_video_width(file, 0), 
					mpeg3_video_height(file, 0), 
 					mpeg3_video_width(file, 0), 
 					mpeg3_video_height(file, 0), 
					MPEG3_RGBAF8888, 
 					0);
  	    	CopyBits (GetPortBitMapForCopyBits(gpGWOffScreen), GetPortBitMapForCopyBits(GetWindowPort(pWindow)), &sourceRect, &sourceRect, srcCopy, NULL); 
		}
		UnlockPixels (hPixmap);
		DisposeGWorld(gpGWOffScreen);
        memoryFree(output_rows);
        
		fprintf(stderr, "Audio streams: %d\n", mpeg3_total_astreams(file));
		for(i = 0; i < mpeg3_total_astreams(file); i++)
		{
			 fprintf(stderr, "  Stream %d: channels %d sample rate %d total samples %ld\n", 
				i, 
				mpeg3_audio_channels(file, i), 
				mpeg3_sample_rate(file, i),
				mpeg3_audio_samples(file, i));
		}
		fprintf(stderr, "Video streams: %d\n", mpeg3_total_vstreams(file));
		for(i = 0; i < mpeg3_total_vstreams(file); i++)
		{
			fprintf(stderr, "  Stream %d: width %d height %d frame rate %0.3f total frames %ld\n", 
				i, 
				mpeg3_video_width(file, i), 
				mpeg3_video_height(file, i), 
				mpeg3_frame_rate(file, i),
				mpeg3_video_frames(file, i));
		}
		
		mpeg3_close(file);
	}