コード例 #1
0
void frameGrabber::parameterCheck(ImageIDL& img, long tolerance)
	{
	if (img.width > iMaxColumns)
		{
		if (tolerance & kSizeTolerance)
			img.width = iMaxColumns;
		else
			throw Miro::EOutOfBounds();
		}
	if (img.width < iMinColumns)
		{
		if (tolerance & kSizeTolerance)
			img.width = iMinColumns;
		else
			throw Miro::EOutOfBounds();
		}
	if (img.height > iMaxRows)
		{
		if (tolerance & kSizeTolerance)
			img.height = iMaxRows;
		else
			throw Miro::EOutOfBounds();
		}
	if (img.height < iMinRows)
		{
		if (tolerance & kSizeTolerance)
			img.height = iMinRows;
		else
			throw Miro::EOutOfBounds();
		}
	if (iNRequests > 0)
		modeCheck(img);
	}
コード例 #2
0
ファイル: invocStore.c プロジェクト: sfsy1989/j2me
/**
 * Function to find a matching entry entry in the queue.
 * The suiteId and classname must match.  If the request param
 * is true then a new Invocation (INIT status) is returned.
 * If false, then an OK, CANCELLED, INITIATED, or ERROR
 * status is selected.  Other status values are ignored.
 *
 * @param suiteId the application suite
 * @param classname a string identifying the entry point
 * @param mode one of {@link #MODE_REQUEST}, {@link #MODE_RESPONSE},
 *    or {@link #MODE_CLEANUP}, {@link #MODE_LREQUEST},
 *    {@link #MODE_LRESPONSE}
 * @return a StoredLink if a matching one is found; NULL otherwise
 */
static StoredLink* invocFind(SuiteIdType suiteId, 
                                const pcsl_string* classname, int mode) {
    StoredLink* curr;
    StoredInvoc* invoc;

    /* Inspect the queue of Invocations and pick one that
     * matches the suiteId and classname.
     */
    for (curr = invocQueue; curr != NULL; ) {
        invoc = curr->invoc;
        /*
         * If the status matches the request
         * and the suite matches and the classname matches.
         */
        if (modeCheck(invoc, mode) &&
            suiteId == invoc->suiteId &&
            pcsl_string_equals(classname, &invoc->classname)) {

            if (mode == MODE_CLEANUP) {
                /* An active or waiting Invocation needs a response */
                if ((invoc->status != STATUS_INIT &&
                     invoc->status != STATUS_ACTIVE) ||
                     (!invoc->responseRequired)) {
                    /* A regular response, discard and continue */
                    StoredLink* next = curr->flink;
                    removeEntry(curr);
                    invocFree(invoc);
                    curr = next;
                    continue;
                }
            }
            return curr;
        }
        curr = curr->flink;
    }
    return NULL;
}
コード例 #3
0
//Need to deal with string-literal input, parallel vs. sequential, user vs. kernal time, EOF-checkery
int main(int argc, char **argv){
    char *prompt = "CMAS> ";
    printf("%s", prompt);
    fflush(stdout);
	const int buffer_len=1024;
    char *buffer=malloc(sizeof(char *)*buffer_len);
	buffer[0]='\0'; //initial value
	char **cmd_arr;
	char mode = 's'; //Mode "bit." 's' means sequential

    while (fgets(buffer, buffer_len, stdin) != NULL) { //works as an EOF checker, according to Prof.
        /* process current command line in buffer */

		killComments(buffer,buffer_len); //Buffer is always a string
		cmd_arr = tokenify(buffer,";"); //array of strings, everything is on the heap
		
		int i = 0;
		int clean_len = 0;
		char ***clean_cmd_arr=malloc(sizeof(char **)*arrLen(cmd_arr));
		char **temp_c;

		printf("Length of cmd_arr: %d\n",arrLen(cmd_arr));

		while(cmd_arr[i]!=NULL){
			temp_c=breakCommand(cmd_arr[i]); //malloced, remember
			free(cmd_arr[i]);
			if(temp_c!=NULL){
				clean_cmd_arr[clean_len++]=temp_c;
			}
			i++;
		}
		free(cmd_arr);
		clean_cmd_arr[clean_len]=NULL;
		
		printf("cca len: %d\n",arrLen2(clean_cmd_arr));
        
        //char *cmd[] = { "/bin/ls", "-l","-t", "-r", ".", NULL };

		i=0;
		char **cmd;
		char temp_m;
		int j;
		_Bool will_exit = 0;
		struct node *kids = NULL;
		for(;clean_cmd_arr[i]!=NULL;i++)  //i < length of clean_cmd_array
		{
			cmd = clean_cmd_arr[i];
			printf("Command: _%s_\n",cmd[0]);

			if(0==strcmp(cmd[0],"exit")){ //exit command given
				will_exit = 1; //will exit later
			}else
			{	 //not an "exit" command
				temp_m = modeCheck(cmd,mode);
				if('n'!=temp_m){
					mode=temp_m;
				}else //no "mode" starting cmd
				{
					insert(execCmd(cmd, mode), &kids);
				}
			}
			j=0;
			for(;j<arrLen(clean_cmd_arr[i]);j++){
				free(clean_cmd_arr[i][j]);
			}
			free(clean_cmd_arr[i]);
		}
		//after all commands executed
	
		struct node *copy = NULL;	
		while (copy != NULL) {
			waitpid(copy->proc, NULL, 0);
			copy = copy->next;
		}
		clear_list(kids);
		free(copy);
		free(clean_cmd_arr);

		if(will_exit){//finished commands and exit given at some point
			struct rusage usage_self, usage_children;
			getrusage(RUSAGE_SELF, &usage_self);
			getrusage(RUSAGE_CHILDREN, &usage_children);
			printf("%ld.%06ld seconds spent in user mode\n", usage_self.ru_utime.tv_sec + usage_children.ru_utime.tv_sec, usage_self.ru_utime.tv_usec + usage_children.ru_utime.tv_usec);
			printf("%ld.%06ld seconds spent in kernel mode\n", usage_self.ru_stime.tv_sec + usage_children.ru_stime.tv_sec, usage_self.ru_stime.tv_usec + usage_children.ru_stime.tv_usec);
		
			break; //leave while loop
		}

		printf("%s", prompt);
		fflush(stdout);
		//printf("TESTING\n");
    }
	free(buffer);

    return 0;
}