Exemplo n.º 1
0
MX_EXPORT mx_status_type
mxs_xafs_scan_delete_record( MX_RECORD *record )
{
	static const char fname[] = "mxs_xafs_scan_delete_record()";

	MX_SCAN *scan;
	MX_XAFS_SCAN *xafs_scan;

	MX_DEBUG( 2,("%s invoked.", fname));

	if ( record == NULL ) {
		return mx_error( MXE_NULL_ARGUMENT, fname,
		"MX_RECORD pointer passed was NULL." );
	}

	scan = (MX_SCAN *)(record->record_superclass_struct);

	if ( scan != NULL ) {
		if ( scan->missing_record_array != NULL ) {
			int i;

			for ( i = 0; i < scan->num_missing_records; i++ ) {
				mx_delete_record(
				    scan->missing_record_array[i] );
			}

			mx_free( scan->missing_record_array );
		}

		xafs_scan = (MX_XAFS_SCAN *) scan->record->record_class_struct;

		if ( xafs_scan != NULL ) {

			record->record_type_struct = NULL;

			mx_free( xafs_scan );

			record->record_class_struct = NULL;
		}

		if ( scan->datafile.x_motor_array != NULL ) {
			mx_free( scan->datafile.x_motor_array );
		}

		if ( scan->plot.x_motor_array != NULL ) {
			mx_free( scan->plot.x_motor_array );
		}

		mx_free( scan );

		scan = NULL;
	}

	return MX_SUCCESSFUL_RESULT;
}
Exemplo n.º 2
0
static void mx_free_rrlist(struct mx_rrlist_t *p)
{
	struct mx_rrlist_t *q;
	while (p != NULL) {
		q = p->next;
		mx_free(p);
		p = q;
	}
}
Exemplo n.º 3
0
void free_mx_list(struct mxlist_t *p)
{
	struct mxlist_t *q;
	while (p != NULL) {
		q = p->next;
		mx_free(p);
		p = q;
	}
}
Exemplo n.º 4
0
MX_EXPORT mx_status_type
mxd_soft_mce_delete_record( MX_RECORD *record )
{
	MX_MCE *mce;

	if ( record == (MX_RECORD *) NULL ) {
		return MX_SUCCESSFUL_RESULT;
	}

	mce = (MX_MCE *) record->record_class_struct;

	if ( mce != (MX_MCE *) NULL ) {
		if ( mce->motor_record_array != (MX_RECORD **) NULL ) {
			mx_free( mce->motor_record_array );
		}
		mx_free( record->record_class_struct );
	}

	if ( record->record_type_struct != NULL ) {
		mx_free( record->record_type_struct );
	}

	return MX_SUCCESSFUL_RESULT;
}
Exemplo n.º 5
0
static struct mxlist_t *getmx_mydns(const char *domain)
{
	static const char szIphlpapiDll[] = "iphlpapi.dll";
	HINSTANCE hIphlpapi;
	GetNetworkParams_t pGetNetworkParams;
	char *info_buf;
	FIXED_INFO *info;
	IP_ADDR_STRING *pa;
	DWORD dw, info_buf_size;
	struct sockaddr_in addr;
	struct mxlist_t *mxlist;

	hIphlpapi = GetModuleHandle(szIphlpapiDll);
	if (hIphlpapi == NULL || hIphlpapi == INVALID_HANDLE_VALUE)
		hIphlpapi = LoadLibrary(szIphlpapiDll);
	if (hIphlpapi == NULL || hIphlpapi == INVALID_HANDLE_VALUE) return NULL;
	pGetNetworkParams = (GetNetworkParams_t)GetProcAddress(hIphlpapi, "GetNetworkParams");
	if (pGetNetworkParams == NULL) return NULL;

	info_buf_size = 16384;
	info_buf = (char *)mx_alloc(info_buf_size);
	dw = info_buf_size;
	info = (FIXED_INFO *)info_buf;
	if (pGetNetworkParams(info, &dw) != ERROR_SUCCESS)
		return NULL;

	for (mxlist=NULL,pa=&info->DnsServerList; pa; pa=pa->Next) {
		if (pa->IpAddress.String == NULL) continue;
		addr.sin_family = AF_INET;
		addr.sin_port = htons(53);
		addr.sin_addr.s_addr = inet_addr(pa->IpAddress.String);
		if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == 0xFFFFFFFF) {
			struct hostent *h = gethostbyname(pa->IpAddress.String);
			if (h == NULL) continue;
			addr.sin_addr = *(struct in_addr *)h->h_addr_list[0];
		}
		if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == 0xFFFFFFFF)
			continue;

		mxlist = my_get_mx_list(&addr, domain);
		if (mxlist != NULL) break;
	}
	mx_free(info_buf);
	return mxlist;
}
Exemplo n.º 6
0
static mx_status_type
mx_network_gaa_get_interface_from_host_address( MX_NETWORK_INTERFACE **ni,
				struct sockaddr *ip_address_struct )
{
	static const char fname[] =
		"mx_network_gaa_get_interface_from_host_address()";

	ULONG output_buffer_length = 0;
	DWORD os_status;
	MX_NETWORK_INTERFACE *ni_ptr;
	uint32_t ipv4_address, ipv4_subnet_mask;
	int i, max_attempts;
	mx_bool_type address_found;
	mx_status_type mx_status;

	typedef ULONG (*GetAdaptersAddresses_type)( ULONG, ULONG, VOID *,
					IP_ADAPTER_ADDRESSES *, ULONG * );

	static GetAdaptersAddresses_type
		ptr_GetAdaptersAddresses = NULL;

	IP_ADAPTER_ADDRESSES *addresses = NULL;
	IP_ADAPTER_ADDRESSES *current_address = NULL;
	IP_ADAPTER_UNICAST_ADDRESS *unicast_address = NULL;
	SOCKET_ADDRESS *socket_address = NULL;
	struct sockaddr *sockaddr = NULL;
	struct sockaddr_in *sockaddr_in = NULL;
	unsigned long local_address = 0;

	if ( ni == (MX_NETWORK_INTERFACE **) NULL ) {
		return mx_error( MXE_NULL_ARGUMENT, fname,
		"The MX_NETWORK_INTERFACE pointer passed was NULL." );
	}
	if ( ip_address_struct == (struct sockaddr *) NULL ) {
		return mx_error( MXE_NULL_ARGUMENT, fname,
		"The ip_address_struct pointer passed was NULL." );
	}
	if ( ip_address_struct->sa_family != AF_INET ) {
		return mx_error( MXE_NOT_YET_IMPLEMENTED, fname,
		"The ip_address_struct argument passed was not for IPV4." );
	}

	/*----*/

	ipv4_address =
		((struct sockaddr_in *) ip_address_struct)->sin_addr.s_addr;

#if MXD_NETWORK_GET_INTERFACE_DEBUG
	MX_DEBUG(-2,("%s: ipv4_address = %#lx", fname, ipv4_address));
#endif

	/* Try to load 'iphlpapi.dll' and get a pointer to the
	 * GetAdapterAddresses() function.
	 */

	mx_status = mx_dynamic_library_get_library_and_symbol(
				"iphlpapi.dll", "GetAdaptersAddresses", NULL,
				(void **) &ptr_GetAdaptersAddresses, 0 );

	if ( mx_status.code != MXE_SUCCESS )
		return mx_status;

	/* Get the list of IP_ADAPTER_ADDRESSES structures for this computer. */

	output_buffer_length = 15000;

	max_attempts = 3;

	for ( i = 0; i < max_attempts; i++ ) {
		addresses = (IP_ADAPTER_ADDRESSES *)
				malloc( output_buffer_length );

		if ( addresses == (IP_ADAPTER_ADDRESSES *) NULL ) {
			return mx_error( MXE_OUT_OF_MEMORY, fname,
			"Ran out of memory trying to allocate a %lu byte "
			"buffer of IP_ADAPTER_ADDRESSES.",
				output_buffer_length );
		}

		os_status = (*ptr_GetAdaptersAddresses)( AF_INET, 0, NULL,
					addresses, &output_buffer_length );

		if ( os_status == ERROR_BUFFER_OVERFLOW ) {
			/* Throw away the buffer that we allocated above,
			 * since we have been told that the buffer needs
			 * to be longer.
			 */

			mx_free( addresses );
			addresses = NULL;
		} else {
			/* Exit the loop early. */

			break;
		}
	}

	if ( os_status != NO_ERROR ) {
		return mx_error( MXE_OPERATING_SYSTEM_ERROR, fname,
		"An attempt to get a list of network adapters failed "
		"with error code = %d.", (int) os_status );
	}

	/* Walk through the list of addresses looking for the address
	 * that we want.
	 */

	address_found = FALSE;

	current_address = addresses;

	while ( current_address != NULL ) {

#if MXD_NETWORK_GET_INTERFACE_DEBUG
	    MX_DEBUG(-2,("*************************************************"));
	    MX_DEBUG(-2,
	    ("%s: adapter name = '%s', friendly name = '%wS', "
	    "description = '%wS'",
		fname, current_address->AdapterName,
		current_address->FriendlyName,
		current_address->Description));
#endif
	    /* If this adapter is not up, then skip over it. */

	    if ( current_address->OperStatus != IfOperStatusUp ) {
		current_address = current_address->Next;
		continue;
	    }

	    /* Otherwise, continue looking at this adapter. */

	    unicast_address = current_address->FirstUnicastAddress;

	    while ( unicast_address != NULL ) {
		socket_address = &(unicast_address->Address);

		ipv4_subnet_mask =
		    mxp_network_get_ipv4_subnet_mask_from_unicast_address(
				unicast_address );

		if ( socket_address != NULL ) {
		    sockaddr = socket_address->lpSockaddr;

		    if ( sockaddr != NULL ) {
			if ( sockaddr->sa_family == AF_INET ) {
			    sockaddr_in = (struct sockaddr_in *) sockaddr;

			    /* The socket address is in network byte order
			     * also known as bigendian, so we must reverse
			     * the endianness.
			     */

			    local_address = sockaddr_in->sin_addr.s_addr;

#if MXD_NETWORK_GET_INTERFACE_DEBUG
			    MX_DEBUG(-2,
				("%s: local address = %lu (%#lx)", fname,
				local_address, local_address));
			    MX_DEBUG(-2,
				("%s: remote address = %lu (%#lx)", fname,
				ipv4_address, ipv4_address));
			    MX_DEBUG(-2,
				("%s: subnet mask = %lu (%#lx)", fname,
				ipv4_subnet_mask, ipv4_subnet_mask));
#endif

			    /* Check to see if this address is in the same
			     * subnet as the IPV4 address passed in one of
			     * the arguments to this function.
			     */

			    if ( ( local_address & ipv4_subnet_mask )
				== ( ipv4_address & ipv4_subnet_mask ) )
			    {
				address_found = TRUE;
			    } else {
				address_found = FALSE;
			    }

			    if ( address_found ) {

#if MXD_NETWORK_GET_INTERFACE_DEBUG
				MX_DEBUG(-2,("%s: address_found = %d",
				    fname, address_found));
#endif

				ni_ptr = (MX_NETWORK_INTERFACE *)
				    malloc( sizeof(MX_NETWORK_INTERFACE) );

				if ( ni_ptr == (MX_NETWORK_INTERFACE *) NULL ) {
				    return mx_error( MXE_OUT_OF_MEMORY, fname,
				    "Ran out of memory trying to allocate an "
				    "MX_NETWORK_INTERFACE structure." );
				}

				WideCharToMultiByte( CP_ACP, 0,
					current_address->FriendlyName, -1,
					ni_ptr->name,
					sizeof(ni_ptr->name),
					NULL, NULL );

#if 1
				strlcpy( ni_ptr->raw_name,
					current_address->AdapterName,
					sizeof(ni_ptr->raw_name) );
#endif

				ni_ptr->ipv4_address = local_address;
				ni_ptr->ipv4_subnet_mask = ipv4_subnet_mask;
				ni_ptr->mtu = current_address->Mtu;
				ni_ptr->net_private = NULL;
			    }
			}
		    }
		}

		if ( address_found ) {
		    break;
		}
		unicast_address = unicast_address->Next;
	    }

	    if ( address_found ) {
		break;
	    }
	    current_address = current_address->Next;
	}

	if ( address_found ) {
		*ni = ni_ptr;

		return MX_SUCCESSFUL_RESULT;
	} else {
		*ni = NULL;

		return mx_error( (MXE_NOT_FOUND | MXE_QUIET), fname,
		"No network interface was found for IP %#lx.",
			ipv4_address );
	}
}
Exemplo n.º 7
0
MX_EXPORT mx_status_type
mx_image_noir_update( MX_IMAGE_NOIR_INFO *image_noir_info )
{
	static const char fname[] = "mx_image_noir_update()";

	MX_RECORD *record;
	MX_IMAGE_NOIR_DYNAMIC_HEADER_VALUE *array_element;
	struct stat noir_header_stat_buf;
	int os_status, saved_errno;
	mx_bool_type read_static_header_file;
	mx_bool_type static_header_file_has_changed;
	FILE *noir_static_header_file;
	size_t noir_static_header_file_size;
	size_t bytes_read;
	unsigned long i;
	mx_status_type mx_status;

	mx_status = MX_SUCCESSFUL_RESULT;

	/* See if we need to update the contents of the static header. */

	static_header_file_has_changed = mx_file_has_changed(
					image_noir_info->file_monitor );

	if ( image_noir_info->static_header_text == NULL ) {
		read_static_header_file = TRUE;
	} else
	if ( static_header_file_has_changed ) {
		read_static_header_file = TRUE;
	} else {
		read_static_header_file = FALSE;
	}

#if MX_IMAGE_NOIR_DEBUG_UPDATE
	if ( read_static_header_file ) {

		MX_DEBUG(-2,("%s: updating static NOIR header from '%s'.",
			fname, image_noir_info->file_monitor->filename ));
	} else {
		MX_DEBUG(-2,("%s: static NOIR header will not be updated.",
			fname));
	}
#endif

	if ( read_static_header_file ) {
		mx_free( image_noir_info->static_header_text );

		os_status = stat( image_noir_info->file_monitor->filename,
					&noir_header_stat_buf );

		if ( os_status != 0 ) {
			saved_errno = errno;

			return mx_error( MXE_FILE_IO_ERROR, fname,
			"An attempt to get the current file status of "
			"NOIR static header file '%s' failed with "
			"errno = %d, error message = '%s'.",
				image_noir_info->file_monitor->filename,
				saved_errno, strerror(saved_errno) );
		}

		/* How big is the file? */

		noir_static_header_file_size = noir_header_stat_buf.st_size;

		/* Allocate a buffer big enough to read the file into. */

		image_noir_info->static_header_text =
				malloc( noir_static_header_file_size + 1 );

		if ( image_noir_info->static_header_text == NULL ) {
			return mx_error( MXE_OUT_OF_MEMORY, fname,
			"Ran out of memory trying to allocate a %lu byte "
			"buffer to contain the contents of NOIR static "
			"header file '%s'.",
				(unsigned long) noir_static_header_file_size,
				image_noir_info->file_monitor->filename );
		}

		/* Read in the contents of the NOIR static file header. */

		noir_static_header_file =
			fopen( image_noir_info->file_monitor->filename, "r" );

		if ( noir_static_header_file == (FILE *) NULL ) {
			saved_errno = errno;

			return mx_error( MXE_FILE_IO_ERROR, fname,
			"The attempt to read the NOIR static file header "
			"from file '%s' failed.  "
			"Errno = %d, error message = '%s'.",
				image_noir_info->file_monitor->filename,
				saved_errno, strerror(saved_errno) );
		}

		bytes_read = fread( image_noir_info->static_header_text,
					1, noir_static_header_file_size,
					noir_static_header_file );

		fclose( noir_static_header_file );

		if ( bytes_read != noir_static_header_file_size ) {
			return mx_error( MXE_FILE_IO_ERROR, fname,
			"The number of bytes read (%lu) from NOIR static "
			"header file '%s' was different than the reported "
			"file size of %lu bytes.",
				(unsigned long) bytes_read,
				image_noir_info->file_monitor->filename,
				(unsigned long) noir_static_header_file_size );
		}

		/* Make sure the text is null terminated. */

		image_noir_info->static_header_text[bytes_read] = '\0';
	}

	/* Now update the motor positions and other values used
	 * by the NOIR header.
	 */

	for ( i = 0; i < image_noir_info->dynamic_header_num_records; i++ ) {

		record = image_noir_info->dynamic_header_record_array[i];

		/* FIXME: The following code might be best handled by
		 * an enhanced version of mx_update_record_values().
		 */

		array_element = &image_noir_info->dynamic_header_value_array[i];

		mx_status = mxp_image_noir_info_update_record_value( record,
								array_element );

		if ( mx_status.code != MXE_SUCCESS )
			return mx_status;
	}

	return mx_status;
}
Exemplo n.º 8
0
MX_EXPORT mx_status_type
mx_image_noir_setup( MX_RECORD *mx_imaging_device_record,
		char *detector_name_for_header,
		char *dynamic_header_template_name,
		char *static_header_file_name,
		MX_IMAGE_NOIR_INFO **image_noir_info_ptr )
{
	static const char fname[] = "mx_image_noir_setup()";

	MX_IMAGE_NOIR_INFO *image_noir_info;
	MX_RECORD **record_array;
	MX_RECORD *dynamic_header_string_record;
	MX_RECORD_FIELD *value_field;
	char *dynamic_header_string;
	char *duplicate;
	int split_status, saved_errno;
	int argc, item_argc;
	char **argv, **item_argv;
	int i, j, num_aliases, max_aliases;
	int string_length, local_max_string_length, max_string_length;
	char *ptr, *new_ptr;
	long *alias_dimension_array;
	char ***alias_array;
	MX_IMAGE_NOIR_DYNAMIC_HEADER_VALUE *value_array;
	size_t char_sizeof[3] =
		{ sizeof(char), sizeof(char *), sizeof(char **) };
	mx_status_type mx_status;

#if MX_IMAGE_NOIR_DEBUG_SETUP
	MX_DEBUG(-2,("%s invoked.", fname));
#endif
	if ( mx_imaging_device_record == (MX_RECORD *) NULL ) {
		return mx_error( MXE_NULL_ARGUMENT, fname,
		"The mx_imaging_device_record pointer passed was NULL." );
	}
	if ( image_noir_info_ptr == (MX_IMAGE_NOIR_INFO **) NULL ) {
		return mx_error( MXE_NULL_ARGUMENT, fname,
		"The image_noir_info_ptr pointer passed was NULL." );
	}
	if ( (*image_noir_info_ptr) != (MX_IMAGE_NOIR_INFO *) NULL ) {
		return mx_error( MXE_ILLEGAL_ARGUMENT, fname,
		"The value of *image_noir_info_ptr passed was not NULL.  "
		"Instead, it had the value %p", *image_noir_info_ptr );
	}

	image_noir_info = calloc( 1, sizeof(MX_IMAGE_NOIR_INFO) );

	if ( image_noir_info == (MX_IMAGE_NOIR_INFO *) NULL ) {
		return mx_error( MXE_OUT_OF_MEMORY, fname,
		"Ran out of memory trying to allocate an "
		"MX_IMAGE_NOIR_INFO structure." );
	}

	*image_noir_info_ptr = image_noir_info;

	image_noir_info->mx_imaging_device_record = mx_imaging_device_record;

	if ( detector_name_for_header == NULL ) {
		image_noir_info->detector_name_for_header[0] = '\0';
	} else {
		strlcpy( image_noir_info->detector_name_for_header,
			detector_name_for_header,
			sizeof( image_noir_info->detector_name_for_header ) );
	}

	/*========= Setup static header information =========*/

	if ( ( static_header_file_name == NULL )
	  || ( strlen(static_header_file_name) == 0 ) )
	{
		image_noir_info->file_monitor = NULL;

		mx_warning( "No static NOIR header file was specified "
		"for record '%s'.", mx_imaging_device_record->name );
	} else {
		/* Setup a file monitor for the static part
		 * of the NOIR header.
		 */

		unsigned long access_type = R_OK | MXF_FILE_MONITOR_QUIET;

#if MX_IMAGE_NOIR_DEBUG_SETUP
		MX_DEBUG(-2,
			("%s: Setting up a file monitor for the static NOIR "
			"header file '%s'.",
			fname, static_header_file_name));
#endif

		mx_status = mx_create_file_monitor(
				&(image_noir_info->file_monitor),
				access_type,
				static_header_file_name );

		switch( mx_status.code ) {
		case MXE_SUCCESS:
			/* Do nothing here. */
			break;

		case MXE_NOT_FOUND:
			image_noir_info->file_monitor = NULL;

			mx_warning( "Static NOIR header file '%s' was "
				"not found and will not be monitored.",
				static_header_file_name );
			break;

		default:
			return mx_status;
			break;
		}
	}

	image_noir_info->static_header_text = NULL;
	image_noir_info->static_header_length = 0;

	/*========= Setup dynamic header information =========*/

	image_noir_info->dynamic_header_num_records = 0;

	/* Look for a string variable record in the database whose name
	 * is given by the string 'dynamic_header_template_name'.  It
	 * should contain a list of the records used to generate the
	 * dynamic information used by NOIR image headers.
	 */

	if ( ( dynamic_header_template_name == NULL )
	  || ( strlen(dynamic_header_template_name) == 0 ) )
	{
		mx_warning( "Cannot setup dynamic NOIR header information, "
		"since no dynamic header template name record was specified." );

		return MX_SUCCESSFUL_RESULT;
	}

	dynamic_header_string_record = mx_get_record( mx_imaging_device_record,
						dynamic_header_template_name );

	if ( dynamic_header_string_record == (MX_RECORD *) NULL ) {
		mx_warning( "Cannot setup NOIR dynamic header information, "
		"since the MX database does not contain a record called '%s'.",
		dynamic_header_template_name );

		return MX_SUCCESSFUL_RESULT;
	}

	/* Is this a string variable?  If so, it should have a 1-dimensional
	 * 'value' field with a type of MXFT_STRING.
	 */

	mx_status = mx_find_record_field( dynamic_header_string_record,
						"value", &value_field );

	if ( mx_status.code != MXE_SUCCESS )
		return mx_status;

	if ( ( value_field->num_dimensions != 1 )
	  || ( value_field->datatype != MXFT_STRING ) )
	{
		return mx_error( MXE_TYPE_MISMATCH, fname,
		"The 'value' field of record '%s' used to generate "
		"NOIR image headers is NULL.",
			dynamic_header_string_record->name );
	}

	dynamic_header_string = mx_get_field_value_pointer( value_field );

	if ( dynamic_header_string == (char *) NULL ) {
		return mx_error( MXE_CORRUPT_DATA_STRUCTURE, fname,
		"The field value pointer for field '%s.%s' is NULL.",
			dynamic_header_string_record->name,
			value_field->name );
	}

#if MX_IMAGE_NOIR_DEBUG_SETUP
	MX_DEBUG(-2,("%s: '%s' string = '%s'", fname, 
		dynamic_header_string_record->name,
		dynamic_header_string ));
#endif

	duplicate = strdup( dynamic_header_string );

	if ( duplicate == (char *) NULL ) {
		return mx_error( MXE_OUT_OF_MEMORY, fname,
	  "Ran out of memory trying to make a copy of dynamic_header_string.");
	}

	split_status = mx_string_split( duplicate, " ", &argc, &argv );

	if ( split_status != 0 ) {
		saved_errno = errno;

		mx_free( duplicate );

		switch( saved_errno ) {
		case EINVAL:
			return mx_error( MXE_ILLEGAL_ARGUMENT, fname,
			"One or more of the arguments to mx_string_split() "
			"were invalid." );
			break;
		case ENOMEM:
			return mx_error( MXE_OUT_OF_MEMORY, fname,
			"Ran out of memory trying to parse image_noir_string "
			"into separate strings." );
			break;
		default:
			return mx_error( MXE_UNKNOWN_ERROR, fname,
			"An unexpected errno value %d was returned when "
			"trying to parse image_noir_string.", saved_errno );
			break;
		}
	}

#if MX_IMAGE_NOIR_DEBUG_SETUP
	MX_DEBUG(-2,("%s: argc = %d", fname, argc));
#endif

	image_noir_info->dynamic_header_num_records = argc;

	if ( argc == 0 ) {
		mx_warning( "No dynamic header entries found in record '%s'.",
			dynamic_header_string_record->name );

		return MX_SUCCESSFUL_RESULT;
	}

	record_array = (MX_RECORD **) calloc( argc, sizeof(MX_RECORD *) );

	if ( record_array == (MX_RECORD **) NULL ) {
		return mx_error( MXE_OUT_OF_MEMORY, fname,
		"Ran out of memory trying to allocate a %d element "
		"array of MX_RECORD * pointers.", argc );
	}

	image_noir_info->dynamic_header_record_array = record_array;

	value_array = (MX_IMAGE_NOIR_DYNAMIC_HEADER_VALUE *)
		calloc( argc, sizeof(MX_IMAGE_NOIR_DYNAMIC_HEADER_VALUE) );

	if ( value_array == (MX_IMAGE_NOIR_DYNAMIC_HEADER_VALUE *) NULL ) {
		return mx_error( MXE_OUT_OF_MEMORY, fname,
		"Ran out of memory trying to allocate a %d element "
		"array of MX_IMAGE_NOIR_DYNAMIC_HEADER_VALUE elements.", argc );
	}

	image_noir_info->dynamic_header_value_array = value_array;

	/* What is the maximum number of aliases for a given header value?
	 * We find that out by counting the number of occurrences of the ':'
	 * each of the argv strings above and then use the maximum of those.
	 */

	max_aliases = 0;
	max_string_length = 0;

	for ( i = 0; i < argc; i++ ) {

		num_aliases = 0;
		local_max_string_length = 0;

		ptr = argv[i];

		new_ptr = strchr( ptr, ':' );

		while ( new_ptr != NULL ) {

			num_aliases++;

			ptr = new_ptr;

			ptr++;

			new_ptr = strchr( ptr, ':' );

			if ( new_ptr == NULL ) {
				string_length = strlen(ptr) + 1;
			} else {
				string_length = new_ptr - ptr + 1;
			}

			if ( string_length > local_max_string_length ) {
				local_max_string_length = string_length;
			}
		}

		if ( num_aliases > max_aliases ) {
			max_aliases = num_aliases;
		}

		if ( local_max_string_length > max_string_length ) {
			max_string_length = local_max_string_length;
		}
	}

#if MX_IMAGE_NOIR_DEBUG_SETUP
	MX_DEBUG(-2,("%s: max_aliases = %d", fname, max_aliases));
#endif

	/* Create an array to store the header alias strings in. */

	alias_dimension_array =
		(long *) image_noir_info->dynamic_header_alias_dimension_array;

	if ( ( image_noir_info->dynamic_header_alias_array != NULL )
	  && ( alias_dimension_array[0] != 0 ) )
	{
		/* If present, destroy the old one. */

		mx_status = mx_free_array(
		    image_noir_info->dynamic_header_alias_array );

		if ( mx_status.code != MXE_SUCCESS )
			return mx_status;
	}

	alias_dimension_array[0] = argc;
	alias_dimension_array[1] = max_aliases;
	alias_dimension_array[2] = max_string_length + 1;

	alias_array = mx_allocate_array( MXFT_STRING, 3,
				alias_dimension_array, char_sizeof );

	if ( alias_array == NULL ) {
		return mx_error( MXE_OUT_OF_MEMORY, fname,
		"Ran out of memory trying to allocate a (%lu,%lu,%lu) array "
		"of NOIR header aliases.",
			alias_dimension_array[0],
			alias_dimension_array[1],
			alias_dimension_array[2] );
	}

	image_noir_info->dynamic_header_alias_array = alias_array;

	/* Fill in the contents of mx_noir_header_record_array
	 * and mx_noir_header_alias_array.
	 */

	for ( i = 0; i < argc; i++ ) {

		split_status = mx_string_split( argv[i], ":",
					&item_argc, &item_argv );

		if ( split_status != 0 ) {
			saved_errno = errno;

			mx_status = mx_error( MXE_UNKNOWN_ERROR, fname,
				"Unexpected errno value %d was returned when "
				"trying to parse argv[%d] = '%s'.",
					saved_errno, i, argv[i] );

			mx_free( argv );
			mx_free( duplicate );

			return mx_status;
		}

		if ( item_argc < 1 ) {
			mx_status = mx_error( MXE_ILLEGAL_ARGUMENT, fname,
			"Entry %d in the 'mx_noir_records_list' variable "
			"is empty.", i );

			mx_free( item_argv );
			mx_free( argv );
			mx_free( duplicate );

			return mx_status;
		}
		if ( item_argc < 2 ) {
			mx_status = mx_error( MXE_ILLEGAL_ARGUMENT, fname,
			"Entry %d '%s' in the 'mx_noir_records_list' "
			"only contains the name of an MX record.  "
			"It does not contain any alias values to be used "
			"to show the value of this record in an "
			"MX NOIR image header.", 0, item_argv[0] );

			mx_free( item_argv );
			mx_free( argv );
			mx_free( duplicate );

			return mx_status;
		}

		/* The first item should be the name of an MX record in
		 * the local MX database.
		 */

		record_array[i] = mx_get_record( mx_imaging_device_record,
							item_argv[0] );

		if ( record_array[i] == (MX_RECORD *) NULL ) {
			mx_status = mx_error( MXE_NOT_FOUND, fname,
			"MX record '%s' for 'mx_noir_record_list entry' %d "
			"was not found in the MX database.",
				item_argv[0], i );

			mx_free( item_argv );
			mx_free( argv );
			mx_free( duplicate );

			return mx_status;
		}

#if MX_IMAGE_NOIR_DEBUG_STRINGS
		fprintf(stderr, "%s: record[%d] = '%s'",
			fname, i, record_array[i]->name);
#endif

		/* The subsequent items are the various aliases to be used
		 * in the NOIR header for this MX record.
		 */

		for ( j = 0; j < max_aliases; j++ ) {

			if ( j >= (item_argc - 1) ) {
				alias_array[i][j][0] = '\0';
			} else {
				strlcpy( alias_array[i][j],
					item_argv[j+1],
					max_string_length );
			}
#if MX_IMAGE_NOIR_DEBUG_STRINGS
			fprintf(stderr, ", alias(%d) = '%s'",
				j, alias_array[i][j] );
#endif
		}

#if MX_IMAGE_NOIR_DEBUG_STRINGS
		fprintf(stderr,"\n");
#endif

		mx_free( item_argv );
	}

	/* Discard some temporary data structures. */

	mx_free( argv );
	mx_free( duplicate );

	return MX_SUCCESSFUL_RESULT;
}
Exemplo n.º 9
0
MX_EXPORT DIR *
opendir( const char *name )
{
	static const char fname[] = "opendir()";

	DIR *dir;
	DWORD last_error_code;
	TCHAR message_buffer[100];
	size_t original_length;
	char *name_copy;
	size_t name_copy_length;

	errno = 0;

	/* See if the name pointer is NULL. */

	if ( name == NULL ) {
		errno = ENOENT;
		return NULL;
	}

	/* See if the name is of zero length. */

	if ( name[0] == '\0' ) {
		errno = ENOENT;
		return NULL;
	}

	/*------------------------------------------------------------------*/

	/* Fun Facts for Inquiring Minds Episode 257.
	 *
	 * Hi Kids!  Were you aware that the MSDN entry for FindFirstFile()
	 * contains this pithy statement?
	 *
	 *   An attempt to open a search with a trailing backlash always fails.
	 *
	 * So what does this mean for all of you kids out there in Internet
	 * Land?  Well it means that starting a search for D:\wml using
	 * FindFirstFile() will succeed, but a search using D:\wml\
	 * will fail horribly.  Don't believe me?  Go try it yourself.
	 * I'll wait.
	 *
	 *   ...
	 *
	 * So did you see it?  FindFirstFile() on D:\wml\ returned 
	 * INVALID_HANDLE_VALUE!  Wow, that's a surprise.
	 *
	 * So what do we do about it?  Well the most obvious fix would be
	 * to just zap the trailing backslash with a null character.  That
	 * turns something like D:\wml\ into D:\wml, which we already know
	 * works.  However, ... you might want to try that trick again with
	 * a directory name like D:\.  I'll wait until you do.
	 *
	 *   ...
	 *
	 * So ... You got INVALID_HANDLE_VALUE, didn't you.  Well, the zap
	 * trick turned D:\ into D:, but plain driver names like A:, B:,
	 * C:, D:, etc. are not accepted by FindFirstFile(), no way, no how.
	 *
	 * So what do we do?  As it happens, Microsoft does have some more
	 * verbiage about this:
	 *
	 *   As stated previously, you cannot use a trailing backslash (\) in
	 *   the lpFileName input string for FindFirstFile, therefore it may
	 *   not be obvious how to search root directories. If you want to see
	 *   files or get the attributes of a root directory, the following
	 *   options would apply:
	 *
	 *     To examine files in a root directory, you can use "C:\*" and
	 *     step through the directory by using FindNextFile.
	 *
	 *     To get the attributes of a root directory, use the
	 *     GetFileAttributes function.
	 *
	 * In that case, the fix is to look and see if there is a trailing
	 * backslash and append a '*' character after it.  Easy enough.
	 * And for a bare drive name like D:, we just append two characters,
	 * namely, '\' and '*'.  Wow, that was easy too!
	 *
	 * Oh well.  I can see by the clock that we are out of time now,
	 * so that's it for this episode of "Fun Facts for Inquiring Minds".
	 * Bye Kids!
	 */

	/*------------------------------------------------------------------*/

	/* Allocate a DIR structure to put the results in. */

	dir = malloc(sizeof(DIR));

	if ( dir == NULL ) {
		errno = ENOMEM;
		return NULL;
	}

	/* Save the directory name for use by rewinddir(). */

	strlcpy( dir->directory_name, name, sizeof(dir->directory_name) );

	/* Do we need to append anything to the directory name?
	 *
	 * (See FFIM episode transcript above).
	 */

	original_length = strlen( dir->directory_name );

	name_copy_length = original_length + 4;

	name_copy = malloc( name_copy_length );

	if ( name_copy == NULL ) {
		errno = ENOMEM;
		return NULL;
	}

	strlcpy( name_copy, dir->directory_name, name_copy_length );

	if ( ( name_copy[original_length-1] == '\\' )
	  || ( name_copy[original_length-1] == '/' ) )
	{

		/* Append a '*' after any trailing backslashes. */

		strlcat( name_copy, "*", name_copy_length );
	} else
	if ( original_length == 2 ) {
		if ( name_copy[1] == ':' ) {

			/* Append "\*" after any bare drive names. */

			strlcat( name_copy, "\\*", name_copy_length );
		}
	}

	/* Create a Win32 handle for the find search. */

	dir->find_handle = FindFirstFile( name_copy, &(dir->find_data) );

	mx_free( name_copy );

	if ( dir->find_handle == INVALID_HANDLE_VALUE ) {
		last_error_code = GetLastError();

		mx_win32_error_message( last_error_code,
			message_buffer, sizeof(message_buffer) );

		switch( last_error_code ) {
		case ERROR_FILE_NOT_FOUND:
			mx_error( MXE_NOT_FOUND, fname,
			"The requested directory '%s' does not exist.", name );

			errno = ENOENT;
			break;

		default:
			mx_error( MXE_FILE_IO_ERROR, fname,
			"An error occurred while trying to use "
			"directory '%s'.  "
			"Win32 error code = %ld, error message = '%s'",
				name, last_error_code, message_buffer );

			errno = EIO;
			break;
		}

		free(dir);

		return NULL;
	}

	dir->file_number = 0;

	errno = 0;

	return dir;
}
Exemplo n.º 10
0
MX_EXPORT struct dirent *
readdir( DIR *dir )
{
	static const char fname[] = "readdir()";

	static struct dirent entry;
	LPVOID message_buffer;
	BOOL os_status;
	DWORD last_error_code;

	errno = 0;

	memset( &entry, 0, sizeof(struct dirent) );

	/* See if the dir pointer is NULL. */

	if ( dir == NULL ) {
		errno = EBADF;
		return NULL;
	}

	/* Find the next entry, if needed. */

	if ( dir->file_number > 0 ) {
		os_status = FindNextFile( dir->find_handle, &(dir->find_data) );

		if ( os_status == 0 ) {
			last_error_code = GetLastError();

			if ( last_error_code == ERROR_NO_MORE_FILES ) {
				errno = 0;

				return NULL;
			}

			FormatMessage(
				FORMAT_MESSAGE_ALLOCATE_BUFFER |
				FORMAT_MESSAGE_FROM_SYSTEM |
				FORMAT_MESSAGE_IGNORE_INSERTS,
				NULL,
				last_error_code,
				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
				(LPTSTR) &message_buffer,
				0, NULL );

			mx_error( MXE_FILE_IO_ERROR, fname,
			"FindNextFile() failed with error %ld: %s",
				last_error_code, (char *) message_buffer );

			mx_free( message_buffer );

			errno = EIO;

			return NULL;
		}
	}

	strlcpy(entry.d_name, dir->find_data.cFileName, sizeof(entry.d_name));

	dir->file_number++;

	errno = 0;

	return &entry;
}
Exemplo n.º 11
0
MX_EXPORT mx_status_type
mxd_delta_motor_set_parameter( MX_MOTOR *motor )
{
	static const char fname[] = "mxd_delta_motor_set_parameter()";

	MX_DELTA_MOTOR *delta_motor;
	MX_RECORD *moving_motor_record;
	double fixed_position_value, time_for_move;
	double real_position1, real_position2;
	double *moving_positions;
	long i;
	mx_status_type mx_status;

	delta_motor = NULL;
	moving_motor_record = NULL;

	mx_status = mxd_delta_motor_get_pointers( motor, &delta_motor,
					&moving_motor_record, fname );

	if ( mx_status.code != MXE_SUCCESS )
		return mx_status;

	switch( motor->parameter_type ) {
	case MXLV_MTR_SPEED:
		mx_status = mx_motor_set_speed( moving_motor_record,
						motor->raw_speed );
		break;
	case MXLV_MTR_SPEED_CHOICE_PARAMETERS:
		mx_status = mxd_delta_motor_get_fixed_position_value(
				delta_motor, &fixed_position_value );

		if ( mx_status.code != MXE_SUCCESS )
			return mx_status;

		real_position1 = motor->raw_speed_choice_parameters[0]
					+ fixed_position_value;
		real_position2 = motor->raw_speed_choice_parameters[1]
					+ fixed_position_value;
		time_for_move = motor->raw_speed_choice_parameters[2];

		mx_status = mx_motor_set_speed_between_positions(
					moving_motor_record,
					real_position1, real_position2,
					time_for_move );
		break;
	case MXLV_MTR_SAVE_SPEED:
		mx_status = mx_motor_save_speed( moving_motor_record );
		break;
	case MXLV_MTR_RESTORE_SPEED:
		mx_status = mx_motor_restore_speed( moving_motor_record );
		break;
	case MXLV_MTR_ESTIMATED_MOVE_POSITIONS:
		moving_positions = (double *)
		  calloc( motor->num_estimated_move_positions, sizeof(double) );

		if ( moving_positions == (double *) NULL ) {
			return mx_error( MXE_OUT_OF_MEMORY, fname,
			"Ran out of memory trying to allocate a %ld element "
			"array of positions for motor '%s'.",
				motor->num_estimated_move_positions,
				motor->record->name );
		}

		mx_status = mxd_delta_motor_get_fixed_position_value(
				delta_motor, &fixed_position_value );

		if ( mx_status.code != MXE_SUCCESS ) {
			mx_free( moving_positions );
			return mx_status;
		}

		for ( i = 0; i < motor->num_estimated_move_positions; i++ ) {
			moving_positions[i] =
				motor->estimated_move_positions[i]
				+ fixed_position_value;

#if MXD_DELTA_MOTOR_DEBUG_ESTIMATES
			MX_DEBUG(-2,("%s: delta[%ld] = %f, moving[%ld] = %f",
				fname, i, motor->estimated_move_positions[i],
				i, moving_positions[i]));
#endif
		}

		mx_status = mx_motor_set_estimated_move_positions(
					moving_motor_record,
					motor->num_estimated_move_positions,
					moving_positions );

		mx_free( moving_positions );
		break;

	default:
		mx_status = mx_motor_default_set_parameter_handler( motor );
		break;
	}

	return mx_status;
}
Exemplo n.º 12
0
MX_EXPORT mx_status_type
mxd_energy_motor_set_parameter( MX_MOTOR *motor )
{
	static const char fname[] = "mxd_energy_motor_set_parameter()";

	MX_ENERGY_MOTOR *energy_motor;
	MX_RECORD *dependent_motor_record;
	double real_position1, real_position2, time_for_move;
	double *theta_positions;
	long i;
	mx_status_type mx_status;

	mx_status = mxd_energy_motor_get_pointers( motor, &energy_motor,
					&dependent_motor_record,fname );

	if ( mx_status.code != MXE_SUCCESS )
		return mx_status;

	switch( motor->parameter_type ) {
	case MXLV_MTR_SPEED:
	case MXLV_MTR_BASE_SPEED:
	case MXLV_MTR_MAXIMUM_SPEED:
	case MXLV_MTR_RAW_ACCELERATION_PARAMETERS:
		return mx_error( MXE_ILLEGAL_ARGUMENT, fname,
"Energy pseudomotor '%s' cannot set the value of parameter '%s' (%ld).",
			motor->record->name,
			mx_get_field_label_string( motor->record,
						motor->parameter_type ),
			motor->parameter_type );

	case MXLV_MTR_SPEED_CHOICE_PARAMETERS:
		mx_status =
		    mx_motor_compute_real_position_from_pseudomotor_position(
			motor->record, motor->raw_speed_choice_parameters[0],
			&real_position1, FALSE );

		if ( mx_status.code != MXE_SUCCESS )
			return mx_status;

		mx_status =
		    mx_motor_compute_real_position_from_pseudomotor_position(
			motor->record, motor->raw_speed_choice_parameters[1],
			&real_position2, FALSE );

		if ( mx_status.code != MXE_SUCCESS )
			return mx_status;

		time_for_move = motor->raw_speed_choice_parameters[2];

		mx_status = mx_motor_set_speed_between_positions(
					dependent_motor_record,
					real_position1, real_position2,
					time_for_move );
		break;

	case MXLV_MTR_SAVE_SPEED:
		mx_status = mx_motor_save_speed( dependent_motor_record );
		break;

	case MXLV_MTR_RESTORE_SPEED:
		mx_status = mx_motor_restore_speed( dependent_motor_record );
		break;

	case MXLV_MTR_ESTIMATED_MOVE_POSITIONS:
		theta_positions = (double *)
		  calloc( motor->num_estimated_move_positions, sizeof(double) );

		if ( theta_positions == (double *) NULL ) {
			return mx_error( MXE_OUT_OF_MEMORY, fname,
			"Ran out of memory trying to allocate a %ld element "
			"array of theta positions for motor '%s'.",
				motor->num_estimated_move_positions,
				motor->record->name );
		}

#if MXD_ENERGY_DEBUG_ESTIMATES
		MX_DEBUG(-2,("%s: num_estimated_move_positions = %ld",
			fname, motor->num_estimated_move_positions));
#endif
		for ( i = 0; i < motor->num_estimated_move_positions; i++ ) {
			mx_status = mxd_energy_motor_convert_energy_to_theta(
					motor, energy_motor, "convert to",
					motor->estimated_move_positions[i],
					&(theta_positions[i]) );

			if ( mx_status.code != MXE_SUCCESS ) {
				mx_free( theta_positions );
				return mx_status;
			}

#if MXD_ENERGY_DEBUG_ESTIMATES
			MX_DEBUG(-2,("%s: energy[%ld] = %f, theta[%ld] = %f",
				fname, i, motor->estimated_move_positions[i],
				i, theta_positions[i]));
#endif
		}

		mx_status = mx_motor_set_estimated_move_positions(
					dependent_motor_record,
					motor->num_estimated_move_positions,
					theta_positions );

		mx_free( theta_positions );
		break;

	default:
		mx_status = mx_motor_default_set_parameter_handler( motor );
		break;
	}

	return mx_status;
}
Exemplo n.º 13
0
static struct mxlist_t *my_get_mx_list2(struct sockaddr_in *dns_addr, const char *domain, int *err_stat)
{
	int sock, reply_len, rrcode, buf_size;
	int loc_retry;
	struct timeval tv;
	struct fd_set fds;
	unsigned char *buf;
	unsigned short query_fl;
	struct dnsreq_t *reply_hdr;
	struct mx_rrlist_t *rrlist=NULL, *rr1;
	struct mxlist_t *mxlist_root, *mxlist_top, *mxlist_new;

	*err_stat = 1;

	buf_size = 4096;
	buf = (char *)mx_alloc(buf_size);
	if (buf == NULL) return NULL;

	sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if (sock == 0 || sock == INVALID_SOCKET) {
		mx_free(buf);
		return NULL;
	}

	for (loc_retry=0; loc_retry<2; loc_retry++) {
		mxlist_root = mxlist_top = NULL;

		if (loc_retry == 0)
			query_fl = htons(0x0100);
		else
			query_fl = htons(0);

		if (mx_make_query(sock, dns_addr, domain, query_fl))
			continue;

		FD_ZERO(&fds); FD_SET(sock, &fds);
		tv.tv_sec = 12; tv.tv_usec = 0;
		if (select(0, &fds, NULL, NULL, &tv) <= 0)
			continue;

		memset(buf, '\0', sizeof(buf));
		reply_len = recv(sock, buf, buf_size,0);
		if (reply_len <= 0 || reply_len <= sizeof(struct dnsreq_t))
			continue;

		reply_hdr = (struct dnsreq_t *)buf;

		rrcode = ntohs(reply_hdr->flags) & 0x0F;
		if (rrcode == 3) {
			*err_stat = 2;
			break;
		}
		if ((rrcode == 2) && (ntohs(reply_hdr->flags) & 0x80)) {
			*err_stat = 2;
			break;
		}
		if (rrcode != 0)
			continue;

		rrlist = mx_parse_rr(buf, reply_len);
		if (rrlist == NULL)
			continue;

		mxlist_root = mxlist_top = NULL;
		for (rr1=rrlist; rr1; rr1=rr1->next) {
			if ((rr1->rr_class != CLASS_IN) || (rr1->rr_type != TYPE_MX) || (rr1->rdlen < 3))
				continue;
			mxlist_new = (struct mxlist_t *)mx_alloc(sizeof(struct mxlist_t));
			if (mxlist_new == NULL) break;
			memset(mxlist_new, 0, sizeof(struct mxlist_t));

			mxlist_new->pref = ntohs(*(WORD *)(buf+rr1->rdata_offs+0));
			mx_decode_domain(buf, rr1->rdata_offs+2, reply_len, mxlist_new->mx);
			if (mxlist_new->mx[0] == 0) {
				mx_free(mxlist_new);
				continue;
			}

			if (mxlist_top == NULL) {
				mxlist_root = mxlist_top = mxlist_new;
			} else {
				mxlist_top->next = mxlist_new;
				mxlist_top = mxlist_new;
			}
		}

		if (mxlist_root == NULL) {
			mx_free_rrlist(rrlist);
			continue;
		}

		mx_free_rrlist(rrlist);
		break;
	}
	mx_free(buf);
	closesocket(sock);
	return mxlist_root;
}
Exemplo n.º 14
0
static mx_status_type
mx_network_giat_get_interface_from_host_address( MX_NETWORK_INTERFACE **ni,
				struct sockaddr *ip_address_struct )
{
	static const char fname[] =
		"mx_network_giat_get_interface_from_host_address()";

	MX_NETWORK_INTERFACE *ni_ptr;
	uint32_t ipv4_address, mib_ipv4_address, mib_ipv4_subnet_mask;
	MIB_IPADDRTABLE *addresses = NULL;
	MIB_IPADDRROW *address_entry_table = NULL;
	MIB_IPADDRROW *address_entry = NULL;
	long n, num_addresses;
	ULONG address_table_size;
	DWORD os_status;
	int i, max_attempts;
	mx_bool_type address_found;
	mx_status_type mx_status;

	typedef ULONG (*GetIpAddrTable_type)(MIB_IPADDRTABLE *, ULONG *, BOOL);

	static GetIpAddrTable_type
		ptr_GetIpAddrTable = NULL;

	if ( ni == (MX_NETWORK_INTERFACE **) NULL ) {
		return mx_error( MXE_NULL_ARGUMENT, fname,
		"The MX_NETWORK_INTERFACE pointer passed was NULL." );
	}
	if ( ip_address_struct == (struct sockaddr *) NULL ) {
		return mx_error( MXE_NULL_ARGUMENT, fname,
		"The ip_address_struct pointer passed was NULL." );
	}
	if ( ip_address_struct->sa_family != AF_INET ) {
		return mx_error( MXE_NOT_YET_IMPLEMENTED, fname,
		"The ip_address_struct argument passed was not for IPV4." );
	}

	/*----*/

	ipv4_address =
		((struct sockaddr_in *) ip_address_struct)->sin_addr.s_addr;

#if MXD_NETWORK_GET_INTERFACE_DEBUG
	MX_DEBUG(-2,("%s: ipv4_address = %#lx", fname, ipv4_address));
#endif

	/* Try to load 'iphlpapi.dll' and get a pointer to the
	 * GetIpAddrTable() function.
	 */

	mx_status = mx_dynamic_library_get_library_and_symbol(
				"iphlpapi.dll", "GetIpAddrTable", NULL,
				(void **) &ptr_GetIpAddrTable, 0 );

	if ( mx_status.code != MXE_SUCCESS )
		return mx_status;

	/* Get the MIB_IPADDRTABLE structure for this computer. */

	address_table_size = 15000;

	max_attempts = 3;

	for ( i = 0; i < max_attempts; i++ ) {
		addresses = (MIB_IPADDRTABLE *)
				malloc( address_table_size );

		if ( addresses == (MIB_IPADDRTABLE *) NULL ) {
			return mx_error( MXE_OUT_OF_MEMORY, fname,
			"Ran out of memory trying to allocate a %lu byte "
			"MIB_IPADDRTABLE structure.",
				address_table_size );
		}

		os_status = (*ptr_GetIpAddrTable)( addresses,
						&address_table_size,
						FALSE );

		if ( os_status == ERROR_INSUFFICIENT_BUFFER ) {
			/* Throw away the buffer that we allocated above,
			 * since we have been told that the buffer needs
			 * to be longer.
			 */

			mx_free( addresses );
			addresses = NULL;
		} else {
			/* Exit the loop early. */

			break;
		}
	}

	if ( os_status != NO_ERROR ) {
		return mx_error( MXE_OPERATING_SYSTEM_ERROR, fname,
		"An attempt to get a list of network adapters failed "
		"with error code = %d.", (int) os_status );
	}

	num_addresses = addresses->dwNumEntries;

#if MXD_NETWORK_GET_INTERFACE_DEBUG
	MX_DEBUG(-2,("%s: num_addresses = %ld", fname, num_addresses ));
#endif

	if ( num_addresses <= 0 ) {
		return mx_error( MXE_NOT_AVAILABLE, fname,
	    "No network adapters are available.  This should never happen.");
	}

	address_entry_table = addresses->table;

	address_found = FALSE;

	for ( n = 0; n < num_addresses; n++ ) {
		address_entry = &address_entry_table[n];

		mib_ipv4_address = (uint32_t) address_entry->dwAddr;
		mib_ipv4_subnet_mask = (uint32_t) address_entry->dwMask;

#if MXD_NETWORK_GET_INTERFACE_DEBUG
		MX_DEBUG(-2,
		("%s: mib_ipv4_address = %#lx, mib_ipv4_subnet_mask = %#lx",
			fname, mib_ipv4_address, mib_ipv4_subnet_mask ));
#endif

		if ( (ipv4_address & mib_ipv4_subnet_mask)
		  == (mib_ipv4_address & mib_ipv4_subnet_mask) )
		{
			address_found = TRUE;
			break;
		}
	}

	if ( address_found == FALSE ) {
		*ni = NULL;

		return mx_error( (MXE_NOT_FOUND | MXE_QUIET), fname,
		"No network interface was found for IP %#lx.",
			(unsigned long) ipv4_address );
	}

#if MXD_NETWORK_GET_INTERFACE_DEBUG
	MX_DEBUG(-2,("%s: address_found = %d", fname, address_found));
#endif

	ni_ptr = (MX_NETWORK_INTERFACE *)
		    malloc( sizeof(MX_NETWORK_INTERFACE) );

	if ( ni_ptr == (MX_NETWORK_INTERFACE *) NULL ) {
		return mx_error( MXE_OUT_OF_MEMORY, fname,
			"Ran out of memory trying to allocate an "
			"MX_NETWORK_INTERFACE structure." );
	}

	strlcpy( ni_ptr->name, "", sizeof(ni_ptr->name) );
	strlcpy( ni_ptr->raw_name, "", sizeof(ni_ptr->name) );

	ni_ptr->ipv4_address = mib_ipv4_address;
	ni_ptr->ipv4_subnet_mask = mib_ipv4_subnet_mask;
	ni_ptr->mtu = 0;
	ni_ptr->net_private = NULL;

	*ni = ni_ptr;

	/* FIXME: For some reason, we crash with a NULL pointer exception
	 * here unless we put _two_ return statements here.  No idea why.
	 */

	return MX_SUCCESSFUL_RESULT;
	return MX_SUCCESSFUL_RESULT;
}
Exemplo n.º 15
0
int
motor_exec_common( char *script_name, int verbose_flag )
{
	COMMAND *command;
	FILE *script_file;
	int cmd_argc;
	char **cmd_argv = NULL;
	char *split_buffer = NULL;
	char buffer[256];
	int buffer_length, whitespace_length;
	int status, end_of_file;
	char *name_of_found_script;
	unsigned long flags;

	flags = MXF_FPATH_TRY_WITHOUT_EXTENSION \
		| MXF_FPATH_LOOK_IN_CURRENT_DIRECTORY;

	name_of_found_script = mx_find_file_in_path_old( script_name,
						MTR_EXTENSION,
						"MX_MOTOR_PATH",
						flags );

	if ( name_of_found_script == NULL ) {
		fprintf( output,
	"exec: The command script '%s' was not found in the MX_MOTOR_PATH "
	"or in the current directory.\n",
			script_name );
		return FAILURE;
	}

	script_file = fopen( name_of_found_script, "r" );

	if ( script_file == NULL ) {
		fprintf( output,
		"exec: The command script '%s' is read protected.\n",
			name_of_found_script );

		mx_free( name_of_found_script );
		return FAILURE;
	}

	if ( verbose_flag )
		fprintf( output, "*** Script '%s' invoked.\n",
			name_of_found_script );

	mx_free( name_of_found_script );

	/* Execute the commands in the script one line at a time. */

	status = SUCCESS;
	end_of_file = FALSE;

	while ( status == SUCCESS && end_of_file == FALSE ) {
		/* Read a line from the script. */

		mx_fgets( buffer, sizeof buffer, script_file );

		if ( feof(script_file) ) {
			end_of_file = TRUE;
			continue;   /* cycle the while() loop. */
		}

		if ( ferror(script_file) ) {
			status = FAILURE;
			continue;   /* cycle the while() loop. */
		}

		buffer_length = (int) strlen( buffer );

		if ( verbose_flag )
			fprintf( output, "*** %s\n", buffer );

		/* Is this a comment line?
		 *
		 * First skip over any leading spaces or tabs.
		 */

		whitespace_length = (int) strspn( buffer, " \t" );

		if ( whitespace_length < buffer_length ) {
			/* If the first non-whitespace character is
			 * a comment character '#', then skip over
			 * this line.
			 */

			if ( buffer[whitespace_length] == '#' ) {
				/* Go back to the top of the while() loop
				 * to read another line.
				 */

				continue;	
			}
		}

		/* Parse the supplied command line. */

		status = cmd_split_command_line( buffer,
					&cmd_argc, &cmd_argv, &split_buffer );

		if ( status == FAILURE ) {
			cmd_free_command_line( cmd_argv, split_buffer );
			fclose( script_file );
			return FAILURE;
		}

		if ( cmd_argc < 1 ) {
			fprintf( output, "%s: Invalid command line '%s'.\n",
				name_of_found_script, buffer );

			status = FAILURE;
			cmd_free_command_line( cmd_argv, split_buffer );
			continue;	/* cycle the while() loop. */
		}

		if ( cmd_argc == 1 ) {
			/* A blank line was read.  Do nothing. */

			cmd_free_command_line( cmd_argv, split_buffer );
		} else {
			command = cmd_get_command_from_list(
				command_list_length, command_list,
				cmd_argv[1] );

			if ( command == (COMMAND *) NULL ) {
				fprintf( output,
				"%s: Unrecognized motor command '%s'.\n",
					name_of_found_script, cmd_argv[1] );

				status = FAILURE;
				cmd_free_command_line( cmd_argv, split_buffer );
				continue;  /* cycle the while() loop. */
			}

			/* Invoke the function. */

			status
			= (*(command->function_ptr))( cmd_argc, cmd_argv );

			cmd_free_command_line( cmd_argv, split_buffer );
		}
	}

	fclose( script_file );

	return status;
}
Exemplo n.º 16
0
MX_EXPORT mx_status_type
mxv_fix_regions_send_variable( MX_VARIABLE *variable )
{
	static const char fname[] = "mxv_fix_regions_send_variable()";

	MX_FIX_REGIONS *fix_regions_struct = NULL;
	MX_RECORD_FIELD *string_value_field = NULL;
	const char **string_value_pointer = NULL;
	char *string_copy = NULL;
	long i;
	int argc;
	char **argv = NULL;
	size_t argv0_length;
	long fix_type;
	long num_fix_regions;
	long **fix_region_array;
	long *fix_region;
	mx_status_type mx_status;

#if 0
	long j;
#endif

	if ( variable == (MX_VARIABLE *) NULL ) {
		return mx_error( MXE_NULL_ARGUMENT, fname,
		"The MX_VARIABLE pointer passed was NULL." );
	}

	fix_regions_struct = (MX_FIX_REGIONS *)
			variable->record->record_type_struct;

	if ( fix_regions_struct == (MX_FIX_REGIONS *) NULL ) {
		return mx_error( MXE_CORRUPT_DATA_STRUCTURE, fname,
		"The MX_FIX_REGIONS pointer for record '%s' is NULL.",
			variable->record->name );
	}

	num_fix_regions = *(fix_regions_struct->num_fix_regions_ptr);

	fix_region_array = *(fix_regions_struct->fix_region_array_ptr);

	/* Get a pointer to the string field value. */

	mx_status = mx_find_record_field( variable->record, "value",
					&string_value_field );

	if ( mx_status.code != MXE_SUCCESS )
		return mx_status;

	string_value_pointer = mx_get_field_value_pointer( string_value_field );

	for ( i = 0; i < num_fix_regions; i++ ) {
		fix_region = fix_region_array[i];

#if MXV_FIX_REGIONS_DEBUG_VALUE
		MX_DEBUG(-2,("%s: region [%ld] = '%s'",
		fname, i, string_value_pointer[i] ));
#endif

		string_copy = strdup( string_value_pointer[i] );

		if ( string_copy == NULL ) {
			return mx_error( MXE_OUT_OF_MEMORY, fname,
		    "The attempt to copy string %ld for record '%s' failed.",
		    		i, variable->record->name );
		}

		mx_string_split( string_copy, ",", &argc, &argv );

		if ( argc < 5 ) {
			mx_free(argv);
			mx_free(string_copy);

			return mx_error( MXE_UNPARSEABLE_STRING, fname,
			"The string value for fix region[ %ld ] "
			"did not contain 5 components for variable '%s'.",
				i, variable->record->name );
		}

#if 0
		for ( j = 0; j < argc; j++ ) {
			MX_DEBUG(-2,("%s: argv[%ld] = '%s'",
				fname, j, argv[j]));
		}
#endif

		argv0_length = strlen( argv[0] );

		fix_type = -1;

		if ( mx_strncasecmp(argv[0], "horizontal", argv0_length) == 0 ){
			fix_type = MXF_IMAGE_FIX_HORIZONTAL;
		} else
		if ( mx_strncasecmp(argv[0], "vertical", argv0_length) == 0 ) {
			fix_type = MXF_IMAGE_FIX_VERTICAL;
		} else
		if ( mx_strncasecmp(argv[0], "area", argv0_length) == 0 ) {
			fix_type = MXF_IMAGE_FIX_AREA;
		} else {
			mx_status = mx_error( MXE_ILLEGAL_ARGUMENT, fname,
			"Illegal region fix type '%s' requested for "
			"variable '%s'.", argv[0], variable->record->name );

			mx_free(argv);
			mx_free(string_copy);
		}

		fix_region[0] = fix_type;
		fix_region[1] = atol( argv[1] );
		fix_region[2] = atol( argv[2] );
		fix_region[3] = atol( argv[3] );
		fix_region[4] = atol( argv[4] );

		mx_free(argv);
		mx_free(string_copy);
	}

	return MX_SUCCESSFUL_RESULT;
}
Exemplo n.º 17
0
/***   FreeCsDpm   ************************************************************
 *
 */
void
FreeCsDpm(float **cs_dpm)
{
    mx_free((void**)cs_dpm, aln->len, MX_DP);
}
Exemplo n.º 18
0
mx_status_type
mx_list_head_record_show_field( MX_LIST_HEAD *list_head )
{
	static const char fname[] = "mx_list_head_record_show_field()";

	MX_RECORD *mx_record = NULL;
	MX_RECORD_FIELD *mx_field = NULL;
	char *name_copy = NULL;
	char *record_name = NULL;
	char *field_name = NULL;
	char *ptr = NULL;
	void *value_pointer = NULL;
	long i;
	mx_status_type mx_status;

	name_copy = strdup( list_head->show_field );

	if ( name_copy == (char *) NULL ) {
		return mx_error( MXE_OUT_OF_MEMORY, fname,
		"Ran out of memory trying to copy the string '%s'.",
			list_head->show_field );
	}

	record_name = name_copy;

	ptr = strchr( name_copy, '.' );

	if ( ptr == NULL ) {
		field_name = "";
	} else {
		*ptr = '\0';
		field_name = ++ptr;
	}

	fprintf( stderr, "Record field '%s.%s'\n\n", record_name, field_name );

	mx_record = mx_get_record( list_head->record, record_name );

	if ( mx_record == (MX_RECORD *) NULL ) {
		mx_status = mx_error( MXE_NOT_FOUND, fname,
			"The record '%s' was not found in the MX database.",
			record_name );

		mx_free( name_copy );
		return mx_status;
	}

	mx_status = mx_find_record_field( mx_record, field_name, &mx_field );

	if ( mx_status.code != MXE_SUCCESS ) {
		mx_free( name_copy );
		return mx_status;
	}

	mx_free( name_copy );

	value_pointer = mx_get_field_value_pointer( mx_field );

	fprintf( stderr, "  record pointer = %p\n\n", mx_record );

	fprintf( stderr, "  field pointer = %p\n", mx_field );
	fprintf( stderr, "  label_value = %ld\n", mx_field->label_value );
	fprintf( stderr, "  field_number = %ld\n", mx_field->field_number );
	fprintf( stderr, "  datatype = %ld\n", mx_field->datatype );
	fprintf( stderr, "  num_dimensions = %ld\n", mx_field->num_dimensions );
	fprintf( stderr, "  dimension = [" );
	for ( i = 0; i < mx_field->num_dimensions; i++ ) {
		fprintf( stderr, " %ld", mx_field->dimension[i] );
	}
	fprintf( stderr, " ]\n" );
	fprintf( stderr, "  data_element_size = [" );
	for ( i = 0; i < mx_field->num_dimensions; i++ ) {
		fprintf( stderr,
			" %ld", (long) mx_field->data_element_size[i] );
	}
	fprintf( stderr, " ]\n" );
	fprintf( stderr, "  data_pointer = %p\n", mx_field->data_pointer );
	fprintf( stderr, "  value pointer = %p\n", value_pointer );
	fprintf( stderr, "  process_function = %p\n",
					mx_field->process_function );
	fprintf( stderr, "  flags = %#lx\n", mx_field->flags );
	fprintf( stderr, "  timer_interval = %ld\n", mx_field->timer_interval );
	fprintf( stderr, "  value_change_threshold = %g\n",
					mx_field->value_change_threshold );
	fprintf( stderr, "  last_value = %g\n", mx_field->last_value );
	fprintf( stderr, "  value_has_changed_manual_override = %d\n",
			(int) mx_field->value_has_changed_manual_override );
	fprintf( stderr, "  value_changed_test_function = %p\n",
					mx_field->value_changed_test_function );
	fprintf( stderr, "  callback_list = %p\n", mx_field->callback_list );
	fprintf( stderr, "  application_ptr = %p\n", mx_field->application_ptr);
	fprintf( stderr, "  record = %p\n", mx_field->record );
	fprintf( stderr, "  active = %d\n", (int) mx_field->active );
	fprintf( stderr, "\n  value = " );

	if ( (mx_field->num_dimensions > 1)
	  || ((mx_field->datatype != MXFT_STRING)
		  && (mx_field->num_dimensions > 0)) )
	{
		mx_status = mx_print_field_array( stderr,
				mx_record, mx_field, TRUE );
	} else {
		mx_status = mx_print_field_value( stderr,
				mx_record, mx_field, value_pointer, TRUE );
	}

	fprintf( stderr, "\n" );

	return MX_SUCCESSFUL_RESULT;
}
Exemplo n.º 19
0
MX_EXPORT mx_status_type
mxs_xafs_scan_get_parameter( MX_SCAN *scan )
{
	static const char fname[] = "mxs_xafs_scan_get_parameter()";

	MX_XAFS_SCAN *xafs_scan = NULL;
	MX_RECORD *e_minus_e0_record = NULL;
	MX_RECORD *k_record = NULL;
	double *motor_positions = NULL;
	double region_start, region_width, region_step_size;
	double region_measurement_time, region_measurement_duration;
	double total_measurement_duration;
	double region_move_duration, total_move_duration;
	double raw_num_intervals;
	double k, k_start, base_time, counting_time;
	double k_power_law_exponent;
	long i, j, n, num_steps;
	int num_items;
	mx_status_type mx_status;

	if ( scan == (MX_SCAN *) NULL ) {
		return mx_error( MXE_NULL_ARGUMENT, fname,
			"MX_SCAN pointer passed was NULL." );
	}

	xafs_scan = (MX_XAFS_SCAN *)(scan->record->record_class_struct);

	if ( xafs_scan == (MX_XAFS_SCAN *) NULL ) {
		return mx_error( MXE_CORRUPT_DATA_STRUCTURE, fname,
		"MX_XAFS_SCAN pointer for scan record '%s' is NULL.",
			scan->record->name );
	}

	switch( scan->parameter_type ) {
	case MXLV_SCN_ESTIMATED_SCAN_DURATION:

		e_minus_e0_record = mx_get_record( scan->record, "e_minus_e0" );

		if ( e_minus_e0_record == (MX_RECORD *) NULL ) {
			return mx_error( MXE_NOT_FOUND, fname,
			"Motor record 'e_minus_e0' was not found." );
		}

		k_record = mx_get_record( scan->record, "k" );

		if ( k_record == (MX_RECORD *) NULL ) {
			return mx_error( MXE_NOT_FOUND, fname,
			"Motor record 'k' was not found." );
		}

		total_measurement_duration = 0.0;
		total_move_duration = 0.0;

		for ( i = 0; i < xafs_scan->num_energy_regions; i++ ) {
			/* Calculate the region measurement duration. */

			region_start = xafs_scan->region_boundary[i];

			region_width = xafs_scan->region_boundary[i+1]
					- xafs_scan->region_boundary[i];

			region_step_size = xafs_scan->region_step_size[i];

			region_measurement_time =
				xafs_scan->region_measurement_time[i];

			raw_num_intervals = mx_divide_safely( region_width,
							region_step_size );

			num_steps = 1 + mx_round( raw_num_intervals );

			region_measurement_duration =
				num_steps * region_measurement_time;

			total_measurement_duration +=
				region_measurement_duration;
#if DEBUG_ESTIMATED_TIMES
			MX_DEBUG(-2,
			("%s: energy region[%ld] measurement duration = %f",
				fname, i, region_measurement_duration));
#endif
			/* Calculate the region move duration. */

			motor_positions = (double *)
				calloc( num_steps, sizeof(double) );

			if ( motor_positions == (double *) NULL ) {
				return mx_error( MXE_OUT_OF_MEMORY, fname,
				"Ran out of memory trying to allocate a "
				"%ld element array of energy region "
				"motor positions for scan '%s'.",
					num_steps, scan->record->name );
			}

			for ( n = 0; n < num_steps; n++ ) {
				motor_positions[i] = region_start
					+ n * region_step_size;
			}

			mx_status = mx_motor_set_estimated_move_positions(
						e_minus_e0_record,
						num_steps,
						motor_positions );

			mx_free( motor_positions );

			if ( mx_status.code != MXE_SUCCESS )
				return mx_status;

			mx_status = mx_motor_get_total_estimated_move_duration(
						e_minus_e0_record,
						&region_move_duration );

			if ( mx_status.code != MXE_SUCCESS )
				return mx_status;

#if DEBUG_ESTIMATED_TIMES
			MX_DEBUG(-2,
			("%s: energy region[%ld] move duration = %f",
				fname, i, region_move_duration));
#endif
			total_move_duration += region_move_duration;
		}

		if ( scan->record->mx_type == MXS_XAF_K_POWER_LAW ) {

			region_measurement_duration = 0.0;

			j = xafs_scan->num_energy_regions;

			region_start = xafs_scan->region_boundary[j];

			region_width = xafs_scan->region_boundary[j+1]
					- xafs_scan->region_boundary[j];

			region_step_size = xafs_scan->region_step_size[j];

			region_measurement_time =
					xafs_scan->region_measurement_time[j];

			raw_num_intervals = mx_divide_safely( region_width,
							region_step_size );

			num_steps = 1 + mx_round( raw_num_intervals );

			/*---*/

			base_time = xafs_scan->region_measurement_time[0];

			k_start = xafs_scan->region_boundary[j];

			/*---*/

			num_items = sscanf( scan->measurement_arguments,
					"%lg", &k_power_law_exponent );

			if ( num_items != 1 ) {
			    return mx_error( MXE_UNPARSEABLE_STRING, fname,
			    "The timer name cannot be found in the "
			    "measurement arguments field '%s' for scan '%s'.",
				scan->measurement_arguments,
				scan->record->name );
			}

			/*---*/

			k = k_start;

			for ( n = 0; n < num_steps; n++ ) {
				counting_time = base_time *
					pow( k/k_start, k_power_law_exponent );

				region_measurement_duration += counting_time;

				k += region_step_size;
			}

			total_measurement_duration
				+= region_measurement_duration;

#if DEBUG_ESTIMATED_TIMES
			MX_DEBUG(-2,
			("%s: K power law region measurement duration = %f",
				fname, region_measurement_duration));
#endif
			/* Calculate the region move duration. */

			motor_positions = (double *)
					calloc( num_steps, sizeof(double) );

			if ( motor_positions == (double *) NULL ) {
				return mx_error( MXE_OUT_OF_MEMORY,
				fname, "Ran out of memory trying to "
				"allocate a %ld element array of "
				"K region motor positions "
				"for scan '%s'.",
					num_steps, scan->record->name );
			}

			for ( n = 0; n < num_steps; n++ ) {
				motor_positions[i] = region_start
					+ n * region_step_size;
			}

			mx_status = mx_motor_set_estimated_move_positions(
					k_record, num_steps, motor_positions );

			mx_free( motor_positions );

			if ( mx_status.code != MXE_SUCCESS )
				return mx_status;

			mx_status = mx_motor_get_total_estimated_move_duration(
					k_record, &region_move_duration );

			if ( mx_status.code != MXE_SUCCESS )
				return mx_status;

#if DEBUG_ESTIMATED_TIMES
			MX_DEBUG(-2,
			("%s: K power law region move duration = %f",
				fname, region_move_duration));
#endif
			total_move_duration += region_move_duration;

		} else {
			for ( i = 0; i < xafs_scan->num_k_regions; i++ ) {

				/* Calculate the region measurement duration. */

				j = i + xafs_scan->num_energy_regions;

				region_start = xafs_scan->region_boundary[j];

				region_width = xafs_scan->region_boundary[j+1]
					- xafs_scan->region_boundary[j];

				region_step_size =
					xafs_scan->region_step_size[j];

				region_measurement_time =
					xafs_scan->region_measurement_time[j];

				raw_num_intervals = mx_divide_safely(
							region_width,
							region_step_size );

				num_steps = 1 + mx_round( raw_num_intervals );

				region_measurement_duration =
					num_steps * region_measurement_time;
#if DEBUG_ESTIMATED_TIMES
				MX_DEBUG(-2,
				("%s: K region[%ld] measurement duration = %f",
					fname, i, region_measurement_duration));
#endif
				total_measurement_duration
					+= region_measurement_duration;

				/* Calculate the region move duration. */

				motor_positions = (double *)
					calloc( num_steps, sizeof(double) );

				if ( motor_positions == (double *) NULL ) {
					return mx_error( MXE_OUT_OF_MEMORY,
					fname, "Ran out of memory trying to "
					"allocate a %ld element array of "
					"K region motor positions "
					"for scan '%s'.",
						num_steps, scan->record->name );
				}

				for ( n = 0; n < num_steps; n++ ) {
					motor_positions[i] = region_start
						+ n * region_step_size;
				}

				mx_status =
				    mx_motor_set_estimated_move_positions(
						k_record,
						num_steps,
						motor_positions );

				mx_free( motor_positions );

				if ( mx_status.code != MXE_SUCCESS )
					return mx_status;

				mx_status =
				    mx_motor_get_total_estimated_move_duration(
						k_record,
						&region_move_duration );

				if ( mx_status.code != MXE_SUCCESS )
					return mx_status;

#if DEBUG_ESTIMATED_TIMES
				MX_DEBUG(-2,
				("%s: K region[%ld] move duration = %f",
				fname, i, region_move_duration));
#endif
				total_move_duration += region_move_duration;
			}
		}

#if DEBUG_ESTIMATED_TIMES
		MX_DEBUG(-2,("%s: total_measurement_duration = %f",
			fname, total_measurement_duration));
		MX_DEBUG(-2,("%s: total_move_duration = %f",
			fname, total_move_duration));
#endif

		scan->estimated_scan_duration =
			total_measurement_duration + total_move_duration;

#if DEBUG_ESTIMATED_TIMES
		MX_DEBUG(-2,("%s: estimated_scan_duration = %f",
			fname, scan->estimated_scan_duration));
#endif
		break;

	default:
		return mx_scan_default_get_parameter_handler( scan );
		break;
	}
	
	return MX_SUCCESSFUL_RESULT;
}