Branch: Tag:

2006-11-30

2006-11-30 15:31:48 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Added ProviderChoice.

Rev: server/etc/modules/Variable.pmod/module.pmod:1.94

1: - // $Id: module.pmod,v 1.93 2006/05/05 11:05:37 wellhard Exp $ + // $Id: module.pmod,v 1.94 2006/11/30 15:31:48 grubba Exp $      #include <module.h>   #include <roxen.h>
1347:    }   }    + // FIXME: Consider making a ModuleChoice as well.    -  + //! Select a module that provides the specified interface. + class ProviderChoice + { +  inherit StringChoice; +  constant type = "ProviderChoice"; +  static Configuration conf; +  static string provides; +  static string default_id; +  static string local_id; +  +  int low_set(RoxenModule to) +  { +  local_id = _name(to); +  return ::low_set(to); +  } +  +  RoxenModule query() +  { +  RoxenModule res = ::query(); +  if (!res && local_id) { +  // The module might have been reloaded. +  // Try locating it again. +  res = transform_from_form(local_id); +  ::low_set(res); +  } +  return res; +  } +  +  array get_choice_list() +  { +  return conf->get_providers(provides); +  } +  +  static string _name(RoxenModule val) +  { +  return val?val->module_local_id():""; +  } +  +  static string _title(RoxenModule val) +  { +  return val?val->query_name():""; +  } +  +  RoxenModule transform_from_form(string local_id, mapping|void v) +  { +  return conf->find_module(local_id); +  } +  +  RoxenModule default_value() +  { +  if (default_id) { +  return transform_from_form(default_id); +  } else { +  array(RoxenModule) providers = get_choice_list(); +  if (sizeof(providers)) { +  // FIXME: Add sorting? +  return providers[0]; +  } +  return 0; +  } +  } +  +  //! @param default_id +  //! The @[RoxenModule.module_local_id] of the default value. +  //! @param provides +  //! The provider string to match modules against. +  //! @param conf +  //! The current configuration. +  static void create(string default_id, int flags, +  string std_name, string std_doc, +  string provides, Configuration conf) +  { +  this_program::provides = provides; +  this_program::default_id = default_id; +  this_program::conf = conf; +  ::create(0, ({}), flags, std_name, std_doc); +  } + } +    // =====================================================================   // List baseclass   // =====================================================================