public void InsertPlugin(ConfigurationPlugIn plugin, int priority)
        {
            int i;

            for (i = 0; i < plugins.Count; i++)
            {
                ALIB.ASSERT_ERROR(plugins[i].prio != priority,
                                  "Configuration.InsertPlugin(): Plug-in with same priority exists");

                if (plugins[i].prio < priority)
                {
                    break;
                }
            }

            PluginAndPrio pap = new PluginAndPrio();

            pap.plugIn = plugin;
            pap.prio   = priority;
            plugins.Insert(i, pap);

            plugin.Parent = this;
        }
Пример #2
0
        // #############################################################################################
        // Internals
        // #############################################################################################

        /** ****************************************************************************************
         * Internal, recursive helper of #Find.
         *
         * @param       domainPath  Path to search.
         * @param       sensitivity Denotes if domain name search is treated case sensitive or not.
         * @param       maxCreate   The maximum number of sub domains that are created if not
         *                          found at the end of the path.
         * @param[out]  wasCreated  Output parameter that is set \c true if domain was not found
         *                          and hence created.
         * @return The domain found or created.
         ******************************************************************************************/
        protected Domain findRecursive(Substring domainPath, Case sensitivity,
                                       int maxCreate, ref bool wasCreated)
        {
            //--- get act sub-name and rest of path
            domainPath.Consume(PathSeparator);
            int endSubName = domainPath.IndexOf(PathSeparator);

            ALIB.ASSERT_ERROR(endSubName != 0, "Internal Error");

            // find end of actual domain name and save rest
            Substring restOfDomainPath = tSubstring2;

            restOfDomainPath.SetNull();
            if (endSubName > 0)
            {
                domainPath.Split(endSubName, restOfDomainPath, 1);
            }

            // search sub-domain
            Domain subDomain = null;

            // "."
            if (domainPath.Equals("."))
            {
                subDomain = this;
            }

            // ".."
            else if (domainPath.Equals(".."))
            {
                subDomain = Parent != null ? Parent : this;
            }


            // search in sub-domain
            else
            {
                int  i;
                bool fixedOnce = false;
                for (;;)
                {
                    for (i = 0; i < SubDomains.Count; i++)
                    {
                        int comparison = SubDomains[i].Name.CompareTo(domainPath, sensitivity);
                        if (comparison >= 0)
                        {
                            if (comparison == 0)
                            {
                                subDomain = SubDomains[i];
                            }
                            break;
                        }
                    }

                    // domain found?
                    if (subDomain != null)
                    {
                        break;
                    }

                    // try and fix name
                    if (!fixedOnce)
                    {
                        fixedOnce = true;

                        bool illegalCharacterFound = false;
                        for (int cp = 0; cp < domainPath.Length(); ++cp)
                        {
                            char c = domainPath.CharAt(cp);
                            if (c < '-' || c > 'z' ||
                                c == '<' || c == '>' ||
                                c == '[' || c == ']' ||
                                c == '=' || c == '?' || c == ';' || c == ':' ||
                                c == '\\' || c == '\'' || c == '.' || c == ','
                                )
                            {
                                illegalCharacterFound = true;
                                domainPath.Buf[domainPath.Start + cp] = '#';
                            }
                        }

                        if (illegalCharacterFound)
                        {
                            continue;
                        }
                    }

                    // create
                    if (maxCreate == 0)
                    {
                        return(null);
                    }
                    wasCreated = true;
                    SubDomains.Insert(i, subDomain = new Domain(this, new AString(domainPath)));
                    maxCreate--;
                    if (maxCreate == 0)
                    {
                        return(subDomain);
                    }

                    break;
                }
            }
            // recursion?
            if (restOfDomainPath.IsNotEmpty())
            {
                domainPath.Set(restOfDomainPath);
                return(subDomain.findRecursive(domainPath, sensitivity, maxCreate, ref wasCreated));
            }

            // that's it
            return(subDomain);
        }
Пример #3
0
 /** ****************************************************************************************
  * Returns logger of given number.
  * @param no  The number of the \e Logger to return.
  * @return The the \e Logger found with number \p no.
  ******************************************************************************************/
 public Logger  GetLogger(int no)
 {
     ALIB.ASSERT_ERROR(no >= 0 && no < (int)Data.Count, "Internal error: Illegal Logger Number");
     return(Data[no].Logger);
 }
Пример #4
0
        // #############################################################################################
        // Interface
        // #############################################################################################

        /** ****************************************************************************************
         * Adds an acquirer.
         * @param newAcquirer The acquirer to add.
         * @return The new number of \e acquirers set.
         ******************************************************************************************/
        public virtual int AddAcquirer(ThreadLock newAcquirer)
        {
            int count = -1;

            #if DEBUG
            bool errAllreadyAdded    = true;
            bool errHasToBeRecursive = false;
            int  errWasAcquired      = 0;
            #endif

            try { ALIB.Lock.Acquire();

                  count = acquirers.Count;

                  // check doubly added
                  if (newAcquirer == null ||
                      acquirers.IndexOf(newAcquirer) < 0)
                  {
                    #if DEBUG
                      errAllreadyAdded = false;
                      errWasAcquired   = DbgCountAcquirements() == 0 ? 0 : 1;
                    #endif

                      // switch on?
                      if (acquirers.Count == 1)
                      {
                        #if DEBUG
                          errAllreadyAdded = false;
                        #endif
                          ThreadLock firstAcquirer = acquirers[0];

                          // non-anonymous acquirer?
                          if (firstAcquirer != null)
                          {
                              if (firstAcquirer.GetMode() == LockMode.Recursive)
                              {
                                  firstAcquirer.Acquire();
                                  SetSafeness(Safeness.Safe);
                                  acquirers.Add(newAcquirer);
                                  count++;
                                  firstAcquirer.Release();
                              }
                            #if DEBUG
                              else
                              {
                                  errHasToBeRecursive = false;
                              }
                            #endif
                          }
                          // critical section: our first acquirer is anonymous. As documented in class,
                          // this must happen only in situations, when we are sure, that we are safe, e.g. still
                          // single threaded execution of process bootstrap.
                          else
                          {
                              // If this assert happens, its only good luck: we detected a misuse. But it should
                              // be very seldom to be detected this way :-/
                            #if DEBUG
                              if (errWasAcquired == 1)
                              {
                                  errWasAcquired = 2;
                              }
                            #endif

                              SetSafeness(Safeness.Safe);
                              acquirers.Add(newAcquirer);
                              count++;
                          }
                      }
                      else
                      {
                          acquirers.Add(newAcquirer);
                      }
                  }
            } finally { ALIB.Lock.Release(); }

            #if DEBUG
            ALIB.ASSERT_ERROR(!errAllreadyAdded, "Acquirer already registered.");
            ALIB.ASSERT_ERROR(!errHasToBeRecursive, "Acquireres need to be in recursive mode ");
            ALIB.ASSERT_ERROR(errWasAcquired != 1, "Already aquired. Hint: Acquirer[0] must not acquire this before adding itself!");
            ALIB.ASSERT_ERROR(errWasAcquired != 2, "Aquired and acquirer[0] anonymous. Misuse of SmartLock!");
            #endif

            return(count);
        }
Пример #5
0
        /** ****************************************************************************************
         * Removes an acquirer.
         * @param acquirerToRemove The acquirer to remove.
         * @return The new number of \e acquirers set.
         ******************************************************************************************/
        public virtual int RemoveAcquirer(ThreadLock acquirerToRemove)
        {
            int  count          = 0;
            bool errNotFound    = true;
            bool errWasAcquired = false;

            try { ALIB.Lock.Acquire();

                #if DEBUG
                  errWasAcquired = DbgCountAcquirements() != 0;
                #endif

                  // search acquirer
                  if (acquirers.IndexOf(acquirerToRemove) >= 0)
                  {
                      errNotFound = false;

                      // switch off?
                      if (acquirers.Count == 2)
                      {
                          ThreadLock acquirer1 = acquirers[0];
                          ThreadLock acquirer2 = acquirers[1];
                          if (acquirer1 == acquirerToRemove)
                          {
                              acquirer1 = null;
                          }
                          if (acquirer2 == acquirerToRemove)
                          {
                              acquirer2 = null;
                          }

                          // Aquire acquirers in their order of appearance
                          if (acquirer1 != null)
                          {
                              acquirer1.Acquire();
                          }
                          if (acquirer2 != null)
                          {
                              acquirer2.Acquire();
                          }
                          SetSafeness(Safeness.Unsafe);
                          acquirers.Remove(acquirerToRemove);
                          if (acquirer2 != null)
                          {
                              acquirer2.Release();
                          }
                          if (acquirer1 != null)
                          {
                              acquirer1.Release();
                          }
                      }

                      // just remove acquirer, keep mode
                      else
                      {
                          acquirers.Remove(acquirerToRemove);
                      }
                  }

                  count = acquirers.Count; } finally { ALIB.Lock.Release(); }

            ALIB.ASSERT_ERROR(!errNotFound, "Acquirer not found.");
            ALIB.ASSERT_ERROR(!errWasAcquired, "Aquired on release. Hint: Acquirers must acquire only when acquired themselves!");
            return(count);
        }
Пример #6
0
        // #############################################################################################
        // public interface
        // #############################################################################################

        /** ****************************************************************************************
         * Constructs a scope info.
         * @param name              The name of the Lox we belong to
         * @param threadDictionary  A dictionary to map thread IDs to user friendly names which is
         *                          managed outside of this class.
         ******************************************************************************************/
        public ScopeInfo(String name, Dictionary <int, String> threadDictionary)
        {
            loxName = name.ToUpper();
            ALIB.ASSERT_ERROR(!loxName.Equals("GLOBAL"), "Name \"GLOBAL\" not allowed for Lox instances");

            this.threadDictionary = threadDictionary;

            cache = new SourceFile[cacheSize = DefaultCacheSize];
            for (int i = 0; i < cacheSize; i++)
            {
                cache[i] = new SourceFile();
            }
            actual = cache[0];

            // read trim rules from config
            // do 2 times, 0== local list, 1== global list
            List <SourcePathTrimRule> trimInfoList;
            AString rules        = new AString();
            AString variableName = new AString();

            for (int trimInfoNo = 0; trimInfoNo < 2; trimInfoNo++)
            {
                // check if done... or set list
                variableName._();
                if (trimInfoNo == 0)
                {
                    trimInfoList = LocalSPTRs;
                    variableName._(loxName);
                }
                else
                {
                    if (GlobalSPTRsReadFromConfig)
                    {
                        continue;
                    }
                    GlobalSPTRsReadFromConfig = true;
                    trimInfoList = GlobalSPTRs;
                    variableName._("GLOBAL");
                }
                variableName._("_SOURCE_PATH_TRIM_RULES");

                // get auto sizes from last session
                rules._();
                if (ALIB.Config.Get(ALox.ConfigCategoryName, variableName, rules) != 0)
                {
                    Tokenizer rulesTok = new Tokenizer();
                    Tokenizer ruleTok  = new Tokenizer();
                    rulesTok.Set(rules, ';');
                    Substring ruleStr;
                    while ((ruleStr = rulesTok.Next()).IsNotEmpty())
                    {
                        try {
                            ruleTok.Set(ruleStr, ',');
                            SourcePathTrimRule rule = new SourcePathTrimRule();
                            rule.Path = new AString();
                            ruleTok.Next();
                            if (!(rule.IsPrefix = !ruleTok.Actual.StartsWith("*")))
                            {
                                ruleTok.Actual.Consume(1);
                            }
                            rule.Path._(ruleTok.Actual);
                            if (rule.Path.CharAtEnd() == '*')
                            {
                                rule.Path.DeleteEnd(1);
                            }
                            if (rule.Path.IsEmpty())
                            {
                                continue;
                            }

                            if (Path.DirectorySeparatorChar == '/')
                            {
                                rule.Path.SearchAndReplaceAll("\\", "/");
                            }
                            else
                            {
                                rule.Path.SearchAndReplaceAll("/", "\\");
                            }


                            rule.IncludeString = ALIB.ReadInclusion(ruleTok.Next());

                            if (ruleTok.HasNext())
                            {
                                ruleTok.Next().ConsumeInteger(out rule.TrimOffset);
                            }

                            rule.Sensitivity = ALIB.ReadCase(ruleTok.Next());
                            trimInfoList.Add(rule);
                        }
                        catch (Exception)
                        {
                            ALIB.ERROR("Error reading source path trim rule from configuration. Invalid String: "
                                       + ruleStr.ToString());
                        }
                    }
                }
            }
        }