📄 cms_in.cc
字号:
/* 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); } /* Check_id so that debug variables for messages missed can be set. */ check_id(header.write_id); return (status);}/* It takes several steps to perform a peek operation on an neutral buffer.*//* 1. Read the encoded header. *//* 2. Decode the header. *//* 3. Check the id and size. *//* 4. If id and size are ok, then read the message. */CMS_STATUS CMS::peek_encoded(){ /* 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 the global memory object exists. */ if (NULL == handle_to_global_data) { rcs_print_error("CMS: handle_to_global_data is NULL.\n"); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Read the encoded header for the message. */ if (-1 == handle_to_global_data->read(encoded_header, encoded_header_size)) { rcs_print_error ("CMS:(%s) Error reading from global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Decode the header and store in header structure. */ decode_header(); /* Determine if the message in the buffer is new to this process. */ if (CMS_READ_OLD == check_id(header.write_id)) { return (CMS_READ_OLD); /* Don't bother reading an old message. */ } /* 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 += encoded_header_size; if (-1 == handle_to_global_data->read(encoded_data, (long) header.in_buffer_size)) { 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 peek operation */ /* when queuing is enabled on a neutral buffer. *//* 1. Read the encoded queuing_header at the beginning of the buffer. *//* 2. Decode the queuing_header for the buffer. *//* 3. Get the head of the queue from the queuing_header. *//* 4. Read the message header at the head of the queue. *//* 5. Decode the message header. *//* 6. Check the id and size. *//* 7. If id and size are ok, */ /* then read the message */CMS_STATUS CMS::queue_peek_encoded(){ 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 we can update the queuing header later. */ queuing_header_offset = handle_to_global_data->offset; /* Read the encoded header for the buffer. */ if (-1 == handle_to_global_data->read(encoded_queuing_header, encoded_queuing_header_size)) { rcs_print_error ("CMS:(%s) Error reading from global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Decode the queuing header and store in the queuing_header structrure. */ decode_queuing_header(); /* Determine if there are any unread messages. */ if (queuing_header.queue_length == 0) { return (status = CMS_READ_OLD); } /* Read the header for the message. */ handle_to_global_data->offset += queuing_header.head; if (-1 == handle_to_global_data->read(encoded_header, encoded_header_size)) { rcs_print_error ("CMS:(%s) Error reading from global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Decode the message header and store in the header structure. */ decode_header(); /* 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 += encoded_header_size; if (-1 == handle_to_global_data->read(encoded_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); } /* Check_id so that debug variables for messages missed can be set. */ check_id(header.write_id); return (status);}/* It takes several steps to perform a write operation. *//* 1. Read the header. *//* 2. Update the header. *//* 3. Write the message. *//* Parameters: */ /* user_data - pointer to where the user stored the message to be written. */CMS_STATUS CMS::write_raw(void *user_data){ long current_header_in_buffer_size; /* Produce error message if process does not have permission to read. */ if (!write_permission_flag) { rcs_print_error("CMS: %s was not configured to write to %s\n", ProcessName, BufferName); return (status = CMS_PERMISSIONS_ERROR); } /* Store the header information to use after reading the header in the buffer. */ current_header_in_buffer_size = header.in_buffer_size; /* Check that handle to global memory object exists. */ if (NULL == handle_to_global_data) { rcs_print_error("CMS: handle_to_global_data is NULL.\n"); return (status = CMS_INTERNAL_ACCESS_ERROR); }#if 0 /* Check that buffer is large enough for this message. */ if (header.in_buffer_size > max_message_size) { rcs_print_error ("CMS:(%s) Message size %ld exceeds maximum for this buffer of %ld.\n", BufferName, header.in_buffer_size, max_message_size); return (status = CMS_INTERNAL_ACCESS_ERROR); }#endif /* Read the header. */ if (-1 == handle_to_global_data->read(&header, sizeof(header))) { rcs_print_error ("CMS:(%s) Error reading from global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Update the header. */ header.was_read = 0; header.write_id++; if (split_buffer) { if ((header.write_id & 1) != toggle_bit) { header.write_id++; } } header.in_buffer_size = current_header_in_buffer_size; if (-1 == handle_to_global_data->write(&header, sizeof(header))) { rcs_print_error("CMS:(%s) Error writing to global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Write the message. */ if (!disable_final_write_raw_for_dma) { handle_to_global_data->offset += sizeof(CMS_HEADER); if (-1 == handle_to_global_data->write(user_data, (long) current_header_in_buffer_size)) { rcs_print_error ("CMS:(%s) Error writing %ld bytes to global memory at offset %X\n (See %s line %d.)\n", BufferName, header.in_buffer_size, user_data, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } } return (status = CMS_WRITE_OK);}/* It takes several steps to perform a write operation when queuing is enabled. *//* 1. Read the qeuing header at the begining of the buffer. *//* 2. Determine the amount of free space and where the next node can be placed.*//* 3. Set up message header from info in the queuing header. *//* 4. Write the message header and message at the tail of the queue. *//* 5. Update the queuing header. *//* Parameters: */ /* user_data - pointer to where the user stored the message to be written. */CMS_STATUS CMS::queue_write_raw(void *user_data){ CMS_HEADER current_header; long queuing_header_offset; long original_tail; /* Produce error message if process does not have permission to read. */ if (!write_permission_flag) { rcs_print_error("CMS: %s was not configured to write to %s\n", ProcessName, BufferName); return (status = CMS_PERMISSIONS_ERROR); } /* Store the header information to use after reading the header in the buffer. */ current_header = header; /* Check that the handle to the global memory object 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 we can update the queuing header later. */ queuing_header_offset = handle_to_global_data->offset; /* Read the queuing header at the beginning of 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__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Determine amount of free space and location of next node. */ if (handle_to_global_data->size - queuing_header.tail - queuing_header_offset > ((long) (header.in_buffer_size + sizeof(CMS_HEADER))) && queuing_header.tail > queuing_header.head) { free_space = handle_to_global_data->size - queuing_header.tail - queuing_header_offset; } else if (queuing_header.tail < queuing_header.head) { free_space = queuing_header.head - queuing_header.tail; } else if (queuing_header.head > ((long) (queuing_header_offset + sizeof(CMS_QUEUING_HEADER) + (header.in_buffer_size + sizeof(CMS_HEADER))))) { queuing_header.end_queue_space = queuing_header.tail; queuing_header.tail = sizeof(CMS_QUEUING_HEADER); free_space = queuing_header.head - sizeof(CMS_QUEUING_HEADER) - queuing_header_offset; } else { free_space = 0; } if (queuing_header.queue_length == 0) { queuing_header.head = queuing_header.tail = sizeof(CMS_QUEUING_HEADER); queuing_header.queue_length = 0; queuing_header.end_queue_space = queuing_header.tail; 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); } /* Check to see if there is enough free space. */ if (free_space < ((long) (header.in_buffer_size + sizeof(CMS_HEADER)))) { if (cms_print_queue_free_space || cms_print_queue_full_messages) { rcs_print_error("CMS: %s message queue is full.\n", BufferName); rcs_print_error ("(continued) CMS: Message requires %ld bytes but only %ld bytes are left.\n", header.in_buffer_size, free_space); } return (status = CMS_QUEUE_FULL); } /* Store original tail so we'll know where to store the message. */ original_tail = queuing_header.tail; /* Update the queuing header. */ queuing_header.tail += header.in_buffer_size + sizeof(CMS_HEADER); queuing_header.queue_length++; queuing_header.write_id++; if (queuing_header.end_queue_space < queuing_header.tail) { queuing_header.end_queue_space = queuing_header.tail; } if (-1 == handle_to_global_data->write(&queuing_header, sizeof(CMS_QUEUING_HEADER))) { rcs_print_error("CMS:(%s) Error writing to global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Setup message header. */ header.write_id = queuing_header.write_id; header.was_read = 0; header.in_buffer_size = current_header.in_buffer_size; /* Write the message header. */ handle_to_global_data->offset += original_tail; if (-1 == handle_to_global_data->write(&header, sizeof(header))) { rcs_print_error("CMS:(%s) Error writing to global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Write the message. */ handle_to_global_data->offset += sizeof(CMS_HEADER); if (-1 == handle_to_global_data->write(user_data, (long) header.in_buffer_size)) { 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 = CMS_WRITE_OK);}/* It takes several steps to perform a write operation on a neutral buffer. *//* 1. Read the header. *//* 2. Update the header. *//* 3. Write the message. */CMS_STATUS CMS::write_encoded(){ CMS_HEADER current_header; /* Produce error message if process does not have permission to read. */ if (!write_permission_flag) { rcs_print_error("CMS: %s was not configured to write to %s\n", ProcessName, BufferName); return (status = CMS_PERMISSIONS_ERROR); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -