Beispiel #1
0
 /// @brief Constructor with both limits for validity.
 /// @details Implies upper or equal from `lowerLimit` and less than `upperLimit`.
 /// @param[in] lowerLimit Lower limit for valid version.
 /// @param[in] upperLimit Upper limit for valid version.
 /// @param[in] memberType Type of member to versioning.
 public VersionAttribute(float lowerLimit, float upperLimit, PluginVersioning.memberType memberType)
 {
     ///TODO [ASB] : add support for exceptions trowed by VersRange
     _range      = new VersRange(lowerLimit, upperLimit);
     _memberType = memberType;
     isMandatory = false;
 }
Beispiel #2
0
 /// @brief Add a plugin of the container, given a plugin & versionated member type.
 /// @pre The plugin was revised on requirement for mandatory members (using
 /// PluginVersioning.MandatoryMembersDefined() static method) before call this method.
 /// @param[in] plugin Plugin to reference.
 /// @param[in] MemType Type of member.
 /// @exception VersioningPluginException Problems encountered as versionated member not
 /// valid for the member type, or null plugin.
 public void Add(PluginBase plugin, PluginVersioning.memberType MemType)
 {
     try {
         VersionatedContainer cont = new VersionatedContainer(plugin, MemType);
         if (!cont.IsValidMember())
         {
             throw new VersioningPluginException(
                       "There is no '" + MemType.ToString() + "' defined member in '" +
                       plugin.Name + "' plugin.", plugin);
         }
         else
         {
             this.Add(cont);
         }
     }
     catch (VersioningPluginException e)
     {
         if (e.IsNullPluginBase())
         {
             throw new VersioningPluginException("Plugin reference is NULL, for " + MemType.ToString() + "member type.", e);
         }
         else
         {
             throw e;
         }
     }
 }
Beispiel #3
0
 /// @brief Default constructor.
 /// @details The constructor determines also the version of the member, from the type class
 /// and the member type parameter, but it is possible that it doesn't have one, as the case
 /// of system plugins (logic probe, cogs windows, etc).
 /// @param[in] plugin Reference to plugin.
 /// @param[in] MemType Type of member to select.
 /// @exception VersioningPluginException Null plugin encountered.
 public VersionatedContainer(PluginBase plugin, PluginVersioning.memberType MemType)
 {
     if (plugin == null)
     {
         throw new VersioningPluginException(
                   "Plugin reference is NULL, for new VersionatedContainer() of \"" +
                   MemType.ToString() + "\" member type.");
     }
     ;
     if (!plugin.IsUserPlugin)
     {
         throw new VersioningPluginException(
                   "Plugin \"" +
                   plugin.Name + "\" is system plugin. Versioning is only allowed to user plugins.");
     }
     else
     {
         _plugin   = plugin;
         _membType = MemType;
         //As theorically a PluginBase descendent can have instanciated more than one version
         //of each memberType, below code detects and returns the higher version available.
         //if there is none avalaible, the return value is false.
         if (_plugin.Versioning.GetImplementedMethod(MemType, out _member))
         {
             _version = _member.VersionLow;
         }
         else
         {
             _version = -1.0f;
         }
     }
 }
Beispiel #4
0
        GetVersionatedMethods(PluginVersioning.memberType memberType)
        {
            var result = new List <Tuple <MethodInfo, ParameterInfo[]> >();

            //get the methods list of the plugin
            MethodInfo[] meth = _pluginType.GetMethods(BindingFlags.Instance | BindingFlags.Public);
            //browse the method list
            foreach (MethodInfo mInfo in meth)
            {
                //get the custom attributes for the method
                Object[] attr = mInfo.GetCustomAttributes(typeof(VersionAttribute), true);
                //if there are custom attributes for it
                if (attr.Length > 0)
                {   //browse the attribute
                    foreach (Object obj in attr)
                    {
                        VersionAttribute vers = obj as VersionAttribute;    //cast as VersionAttribute
                        //if it is a VersionAttribute type
                        if (vers != null)
                        {
                            if (vers.MemberType == memberType)  //if type is the same of given parameter
                            {
                                result.Add(
                                    new Tuple <MethodInfo, ParameterInfo[]>(mInfo, mInfo.GetParameters())
                                    );
                            }
                        }
                    }
                }
            }
            return(result);
        }
Beispiel #5
0
 /// @brief Constructor with lower limit of validity.
 /// @details Typically used by a new version of a method (upper range of validity).
 /// Assumed upper or equal from this value up to +infinity.
 /// @param[in] versionFrom Lower limit for valid version.
 /// @param[in] memberType Type of member to versioning.
 public VersionAttribute(float versionFrom, PluginVersioning.memberType memberType)
 {
     //TODO [ASB] : add support for exceptions trowed by VersRange
     _range      = new VersRange(versionFrom);
     _memberType = memberType;
     isMandatory = false;
 }
Beispiel #6
0
        /// @brief Retrieve a list with all the possible parameters for the versionated methods of
        /// the supplied member type.
        /// @param[in] memberType Type of versionated member.
        /// @returns List of tuples name & type of the parameters.
        public SortedList <string, Type> GetPossibleParams(PluginVersioning.memberType memberType)
        {
            var list = new SortedList <string, Type>();

            ParamsByType.TryGetValue(memberType, out list);
            return(list);
        }
Beispiel #7
0
 /// @brief Get the maximum quantity of paramers for the versionated methods of the supplied
 /// member type.
 /// @param memberType Type of versionated member.
 /// @returns Quantity of parameters for the member type.
 public int ParametersQty(PluginVersioning.memberType memberType)
 {
     if ((ParamsByType.Count == 0) | (!ParamsByType.ContainsKey(memberType)))
     {
         return(0);
     }
     else
     {
         SortedList <string, Type> paramList;
         ParamsByType.TryGetValue(memberType, out paramList);
         return(paramList.Count);
     }
 }
Beispiel #8
0
 /// @brief Get the high version implemented method for the given member type of the
 /// Plugin instance.
 /// @details As theorically a PluginBase descendent can have instanciated more than one
 /// version of each memberType, this method detects and returns the higher version available.
 /// @pre It assumes the version number of methods for member type are unique: a validation of that
 /// is needed in the begining of the program or complile time.
 /// @param[in] memberType Type of versionated member to obtain its version.
 /// @param[out] mInfo Information about the upper version instanciated method to use. If exist
 /// it, return the only value; otherwise, a empty structure (filled with 0's and null).
 /// @returns True if there is at least one versionated member of the type supplied as
 /// parameter, or False if there is not.
 /// @note @internal reference on article "How to loop through a SortedList, getting both the key and the value"  http://stackoverflow.com/questions/14013261/how-to-loop-through-a-sortedlist-getting-both-the-key-and-the-value
 public bool GetImplementedMethod(
     PluginVersioning.memberType memberType,
     out PluginVersioning.VersionMemberInfo mInfo)
 {
     mInfo = new PluginVersioning.VersionMemberInfo();
     if (_pluginType == null)
     {
         return(false);
     }
     else
     {
         //Get the list of avalaible versions of this member type.
         var candidates = VersionatedMemberCandidates(memberType);
         if (candidates.Count == 0)    //if there is no method of this type implemented on plugin
         {
             return(false);
         }
         else    //if there at least one method of this type implemented on plugin
         {
             float ver    = -1.0f;
             bool  exists = false;
             //browse the candidates list looking for a method instanciated in derived plugin class
             foreach (KeyValuePair <float, PluginVersioning.VersionMemberInfo> pair in candidates)
             {
                 if (pair.Value.IsDeclaredInDerived)
                 {
                     //remember higher value of key, to update the out parameter with the
                     //corresponding struct later.
                     ver    = ((pair.Key >= ver) ? pair.Key : ver);
                     exists = true;
                 }
             }
             //if exists, and assuming the precondition of the method was validated, next call
             //must retrieve exactly one object.
             if (exists)
             {
                 candidates.TryGetValue(ver, out mInfo);  //update mInfo parameter.
             }
             return(exists);
         }
     }
 }
Beispiel #9
0
 /// @brief Determine if the Container have one reference of the plugin inside.
 /// @note This method is thought to be used in the program.
 /// @param[in] plugin Plugin reference to check its precesence in the collection.
 /// @param[in] MemType Member type to check.
 /// @returns True if exist one instance of the plugin, or False if not.
 public bool Contains(PluginBase plugin, PluginVersioning.memberType MemType)
 {
     if (plugin == null)
     {
         return(false);
     }
     else
     {
         bool exist = false;
         foreach (VersionatedContainer vc in _list)
         {
             exist |= ((vc.Plugin == plugin) & (vc.memberType == MemType));
             if (exist)
             {
                 break;
             }
         }
         return(exist);
     }
 }
Beispiel #10
0
        VersionatedMemberCandidates(PluginVersioning.memberType memberType)
        {
            //prepare the sorted list of candidates to output
            var selMeth = new SortedList <float, VersionMemberInfo>();
            //get the versionated methods of the plugin
            List <Tuple <MethodInfo, ParameterInfo[]> > meth = GetVersionatedMethods(memberType);

            //browse the method list
            foreach (Tuple <MethodInfo, ParameterInfo[]> tupleInfo in meth)
            {
                //get the custom attributes for the method
                Object[] attr = tupleInfo.Item1.GetCustomAttributes(typeof(VersionAttribute), true);
                //if there are custom attributes for it
                if (attr.Length > 0)
                {   //browse the attribute
                    foreach (Object obj in attr)
                    {
                        VersionAttribute vers = obj as VersionAttribute;    //cast as VersionAttribute
                        //if it is a VersionAttribute type
                        if (vers != null)
                        {
                            //create a entry on the sorted list
                            selMeth.Add(
                                vers.VersionFrom,
                                new VersionMemberInfo(
                                    vers.VersionFrom,                               //VersionLow
                                    tupleInfo.Item1,                                //MethodInfo
                                    //does it is instanciated here, so not in base class?
                                    (tupleInfo.Item1.DeclaringType == _pluginType), //IsInherited
                                    vers.IsMandatory,                               //IsMandatory
                                    tupleInfo.Item2                                 //parameter list of the method
                                    )
                                );
                        }
                    }
                }
            }
            return(selMeth);
        }
Beispiel #11
0
        /// @brief Determine if exist into plugin, a implemented member of the type given as
        /// parameter.
        /// @details This method is designed to be used after the plugin is loaded in memory, to
        /// check if it is consistent: ex. when the derived plugin declare on PresentChip() that
        /// it use NotifyOnPins() method, there must exist a definition for OnPinChange() method
        /// correspondly.
        /// @param[in] memberType Type of versionated member to check.
        /// @returns True if there is an implemented member, false if not.
        public bool IsMemberTypeImplemented(PluginVersioning.memberType memberType)
        {
            var temp = GetVersionatedMethods(memberType);

            return(temp.Count > 0);
        }