⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cms_in.cc

📁 Source code for an Numeric Cmputer
💻 CC
📖 第 1 页 / 共 5 页
字号:
	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Read the header for the buffer. */    if (-1 == handle_to_global_data->read(encoded_queuing_header,	    encoded_queuing_header_size)) {	rcs_print_error	    ("CMS: Error reading from global memory for %s at %s:%d\n",	    BufferName, __FILE__, __LINE__);	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Decode the header and store in queuing_header structure. */    decode_queuing_header();    return ((int) (queuing_header.queue_length == 0));}/* Determine whether the message in the buffer has been read at least once. */int CMS::get_msg_count_raw(){    /* Check that the handle to global memory exists. */    if (NULL == handle_to_global_data) {	rcs_print_error("CMS: handle_to_global_data is NULL.\n");	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Read the header for the message. */    if (-1 == handle_to_global_data->read(&header, sizeof(CMS_HEADER))) {	rcs_print_error	    ("CMS: Error reading from global memory for %s at %s:%d",	    BufferName, __FILE__, __LINE__);	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    return (header.write_id);} /* Determine if all of the messages in the buffer have been read. This means     the queue is empty. */int CMS::queue_get_msg_count_raw(){    /* Check that the handle to global memory exists. */    if (NULL == handle_to_global_data) {	rcs_print_error("CMS: handle_to_global_data is NULL.\n");	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Read the header for the buffer. */    if (-1 == handle_to_global_data->read(&queuing_header,	    sizeof(CMS_QUEUING_HEADER))) {	rcs_print_error	    ("CMS: Error reading from global memory for %s at %s:%d\n",	    BufferName, __FILE__, __LINE__);	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    return (header.write_id = queuing_header.write_id);}/* Determine whether the message in the buffer has been read at least once. */int CMS::get_msg_count_encoded(){    /* Check that the handle to global memory exists. */    if (NULL == handle_to_global_data) {	rcs_print_error("CMS: handle_to_global_data is NULL.\n");	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Read the header for the buffer. */    if (-1 == handle_to_global_data->read(encoded_header,	    encoded_header_size)) {	rcs_print_error	    ("CMS: Error reading from global memory for %s at %s:%d\n",	    BufferName, __FILE__, __LINE__);	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Decode the header and store in header structure. */    decode_header();    return ((int) header.write_id);} /* Determine if all of the messages in the buffer have been read. This means     the queue is empty. */int CMS::queue_get_msg_count_encoded(){    /* Check that the handle to global memory exists. */    if (NULL == handle_to_global_data) {	rcs_print_error("CMS: handle_to_global_data is NULL.\n");	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Read the header for the buffer. */    if (-1 == handle_to_global_data->read(encoded_queuing_header,	    encoded_queuing_header_size)) {	rcs_print_error	    ("CMS: Error reading from global memory for %s at %s:%d\n",	    BufferName, __FILE__, __LINE__);	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Decode the header and store in queuing_header structure. */    decode_queuing_header();    return (header.write_id = queuing_header.write_id);} /* Determine if all of the messages in the buffer have been read. This means     the queue is empty. */int CMS::queue_get_queue_length_raw(){    /* Check that the handle to global memory exists. */    if (NULL == handle_to_global_data) {	rcs_print_error("CMS: handle_to_global_data is NULL.\n");	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Read the header for the buffer. */    if (-1 == handle_to_global_data->read(&queuing_header,	    sizeof(CMS_QUEUING_HEADER))) {	rcs_print_error	    ("CMS: Error reading from global memory for %s at %s:%d\n",	    BufferName, __FILE__, __LINE__);	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    return (queuing_header.queue_length);} /* Determine if all of the messages in the buffer have been read. This means     the queue is empty. */int CMS::queue_get_queue_length_encoded(){    /* Check that the handle to global memory exists. */    if (NULL == handle_to_global_data) {	rcs_print_error("CMS: handle_to_global_data is NULL.\n");	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Read the header for the buffer. */    if (-1 == handle_to_global_data->read(encoded_queuing_header,	    encoded_queuing_header_size)) {	rcs_print_error	    ("CMS: Error reading from global memory for %s at %s:%d\n",	    BufferName, __FILE__, __LINE__);	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Decode the header and store in queuing_header structure. */    decode_queuing_header();    return (queuing_header.queue_length);} /* Determine if all of the messages in the buffer have been read. This means     the queue is empty. */int CMS::queue_get_space_available_raw(){    long queuing_header_offset;    /* Check that the handle to global memory exists. */    if (NULL == handle_to_global_data) {	rcs_print_error("CMS: handle_to_global_data is NULL.\n");	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Store the original offset so that we can update the header later. */    queuing_header_offset = handle_to_global_data->offset;    /* Read the header for the buffer. */    if (-1 == handle_to_global_data->read(&queuing_header,	    sizeof(CMS_QUEUING_HEADER))) {	rcs_print_error	    ("CMS: Error reading from global memory for %s at %s:%d\n",	    BufferName, __FILE__, __LINE__);	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Determine amount of free space and location of next node. */    if (queuing_header.tail > queuing_header.head) {	free_space = 0;	if (handle_to_global_data->size - queuing_header.tail -	    queuing_header_offset > 0) {	    free_space =		handle_to_global_data->size - queuing_header.tail -		queuing_header_offset;	}	if (queuing_header.head - sizeof(CMS_QUEUING_HEADER) > 0) {	    free_space += queuing_header.head - sizeof(CMS_QUEUING_HEADER);	}    } else if (queuing_header.tail < queuing_header.head) {	free_space = queuing_header.head - queuing_header.tail;    }    if (queuing_header.queue_length == 0) {	free_space = handle_to_global_data->size	    - sizeof(CMS_QUEUING_HEADER) - queuing_header_offset;    }    if (cms_print_queue_free_space) {	rcs_print("queue free space = %d\n", free_space);	rcs_print(" { head=%d,tail=%d,end=%d,length=%d,id=%d }\n",	    queuing_header.head,	    queuing_header.tail,	    queuing_header.end_queue_space,	    queuing_header.queue_length, queuing_header.write_id);    }    return (free_space);} /* Determine if all of the messages in the buffer have been read. This means     the queue is empty. */int CMS::queue_get_space_available_encoded(){    long queuing_header_offset;    /* Check that the handle to global memory exists. */    if (NULL == handle_to_global_data) {	rcs_print_error("CMS: handle_to_global_data is NULL.\n");	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Store the original offset so that we can update the header later. */    queuing_header_offset = handle_to_global_data->offset;    /* Read the header for the buffer. */    if (-1 == handle_to_global_data->read(encoded_queuing_header,	    encoded_queuing_header_size)) {	rcs_print_error	    ("CMS: Error reading from global memory for %s at %s:%d\n",	    BufferName, __FILE__, __LINE__);	status = CMS_INTERNAL_ACCESS_ERROR;	return 0;    }    /* Decode the header and store in queuing_header structure. */    decode_queuing_header();    /* Determine amount of free space and location of next node. */    if (queuing_header.tail > queuing_header.head) {	free_space = 0;	if (handle_to_global_data->size - queuing_header.tail -	    queuing_header_offset > 0) {	    free_space =		handle_to_global_data->size - queuing_header.tail -		queuing_header_offset;	}	if (queuing_header.head - encoded_queuing_header_size -	    queuing_header_offset > 0) {	    free_space += queuing_header.head - encoded_queuing_header_size -		queuing_header_offset;	}    } else if (queuing_header.tail < queuing_header.head) {	free_space = queuing_header.head - queuing_header.tail;    }    if (queuing_header.queue_length == 0) {	free_space = handle_to_global_data->size	    - encoded_queuing_header_size - queuing_header_offset;    }    if (cms_print_queue_free_space) {	rcs_print("queue free space = %d\n", free_space);	rcs_print(" { head=%d,tail=%d,end=%d,length=%d,id=%d }\n",	    queuing_header.head,	    queuing_header.tail,	    queuing_header.end_queue_space,	    queuing_header.queue_length, queuing_header.write_id);    }    return (free_space);}/* It takes several steps to perform a read operation. *//* 1. Read the header. *//* 2. Check the id and size. *//* 3. If id and size are ok, then read the message and update the header. */CMS_STATUS CMS::read_raw(){    /* Produce error message if process does not have permission to read. */    if (!read_permission_flag) {	rcs_print_error("CMS: %s was not configured to read %s\n",	    ProcessName, BufferName);	return (status = CMS_PERMISSIONS_ERROR);    }    /* Check that the handle to global memory exists. */    if (NULL == handle_to_global_data) {	rcs_print_error("CMS:(%s) handle_to_global_data is NULL.\n",	    BufferName);	return (status = CMS_INTERNAL_ACCESS_ERROR);    }    /* Read the header for the message. */    if (-1 == handle_to_global_data->read(&header, sizeof(CMS_HEADER))) {	rcs_print_error	    ("CMS:(%s) Error reading from global memory at %s:%d\n",	    BufferName, __FILE__, __LINE__);	return (status = CMS_INTERNAL_ACCESS_ERROR);    }    /* Set status to CMS_READ_OLD or CMS_READ_OK */    if (check_id(header.write_id) == CMS_READ_OK) {	/* Check the size of the message. */	if (header.in_buffer_size > max_message_size) {	    rcs_print_error		("CMS:(%s) Message size of %ld exceeds maximum of %ld\n",		BufferName, header.in_buffer_size, max_message_size);	    return (status = CMS_INTERNAL_ACCESS_ERROR);	}	/* Read the message. */	handle_to_global_data->offset += sizeof(CMS_HEADER);	if (-1 ==	    handle_to_global_data->read(subdiv_data,		(long) header.in_buffer_size)) {	    rcs_print_error		("CMS:(%s) Error reading from global memory at %s:%d\n",		BufferName, __FILE__, __LINE__);	    return (status = CMS_INTERNAL_ACCESS_ERROR);	}	handle_to_global_data->offset -= sizeof(CMS_HEADER);    }    /* Update the header. */    header.was_read = 1;    if (-1 == handle_to_global_data->write(&header, sizeof(CMS_HEADER))) {	rcs_print_error("CMS:(%s) Error writing to global memory at %s:%d\n",	    BufferName, __FILE__, __LINE__);	return (status = CMS_INTERNAL_ACCESS_ERROR);    }    return (status);}/* It takes several steps to perform a read operation when queuing is enabled. *//* 1. Read the queuing_header at the beginning of the buffer. *//* 2. Get the head of the queue from the queuing_header. *//* 3. Read the message header at the head of the queue. *//* 4. Check the id and size. *//* 5. If id and size are ok, *//* then read the message and *//* update both the queuing header and message header. */CMS_STATUS CMS::queue_read_raw(){    long queuing_header_offset;    /* Produce error message if process does not have permission to read. */    if (!read_permission_flag) {	rcs_print_error("CMS: %s was not configured to read %s\n",	    ProcessName, BufferName);	return (status = CMS_PERMISSIONS_ERROR);    }    /* Check that the handle to global memory exists. */    if (NULL == handle_to_global_data) {	rcs_print_error("CMS: handle_to_global_data is NULL.\n");	return (status = CMS_INTERNAL_ACCESS_ERROR);    }    /* Store the original offset so that we can update the header later. */    queuing_header_offset = handle_to_global_data->offset;    /* Read the queuing header for the buffer. */    if (-1 == handle_to_global_data->read(&queuing_header,	    sizeof(CMS_QUEUING_HEADER))) {	rcs_print_error	    ("CMS:(%s) Error reading from global memory at %s:%d\n",	    BufferName, __FILE__, __LINE__);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -