[asterisk-scf-commits] asterisk-scf/integration/logger.git branch "filename" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Mar 11 16:11:38 CST 2011


branch "filename" has been updated
       via  2416bede77f0052f3fb2e3e1bccbdc0b725bba9d (commit)
      from  1ce571cc146ef90318b769d7c712fe51ddc744d6 (commit)

Summary of changes:
 server/local-slice/LoggingConfigurationIf.ice |   73 +++++
 server/src/Configuration.cpp                  |  361 +++++++++++++++++++++++++
 server/src/Configuration.h                    |   66 +++++
 3 files changed, 500 insertions(+), 0 deletions(-)
 create mode 100644 server/local-slice/LoggingConfigurationIf.ice
 create mode 100644 server/src/Configuration.cpp
 create mode 100644 server/src/Configuration.h


- Log -----------------------------------------------------------------
commit 2416bede77f0052f3fb2e3e1bccbdc0b725bba9d
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Mar 11 16:07:56 2011 -0600

    Here's the first try at configuration implementation.
    
    It only allows for the log file to be set at the moment.
    It's untested, and I'm pushing it mainly so that I can get
    help with a compilation problem.

diff --git a/server/local-slice/LoggingConfigurationIf.ice b/server/local-slice/LoggingConfigurationIf.ice
new file mode 100644
index 0000000..c75f4f1
--- /dev/null
+++ b/server/local-slice/LoggingConfigurationIf.ice
@@ -0,0 +1,73 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#pragma once
+#include <AsteriskSCF/System/Component/ConfigurationIf.ice>
+
+module AsteriskSCF
+{
+module System
+{
+module Logger
+{
+["suppress"]
+module V1
+{
+
+   /**
+    * Local visitor class for visiting Logger configuration groups
+    */
+   ["visitor"] local class LoggerConfigurationGroupVisitor extends AsteriskSCF::System::Configuration::V1::ConfigurationGroupVisitor
+   {
+   };
+
+   /**
+    * Generic Logger configuration group
+    */
+   ["visitor:LoggerConfigurationGroupVisitor"] class LoggerConfigurationGroup extends AsteriskSCF::System::Configuration::V1::ConfigurationGroup
+   {
+   };
+
+   /**
+    * General Logger configuration group that contains general items related to the Logger component as a whole
+    */
+   class LoggerGeneralGroup extends LoggerConfigurationGroup
+   {
+   };
+
+   /**
+    * Local visitor class for visiting Logger configuration items
+    */
+   ["visitor"] local class LoggerConfigurationItemVisitor extends AsteriskSCF::System::Configuration::V1::ConfigurationItemVisitor
+   {
+   };
+
+   /**
+    * Generic Logger configuration item
+    */
+   ["visitor:LoggerConfigurationItemVisitor"] class LoggerConfigurationItem extends AsteriskSCF::System::Configuration::V1::ConfigurationItem
+   {
+   };
+
+   class FileItem extends LoggerConfigurationItem
+   {
+       string fileName;
+   };
+
+}; //end module V1
+}; //end module Logger
+}; //end module System
+}; //end module AsteriskSCF
diff --git a/server/src/Configuration.cpp b/server/src/Configuration.cpp
new file mode 100644
index 0000000..a190110
--- /dev/null
+++ b/server/src/Configuration.cpp
@@ -0,0 +1,361 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#include "Configuration.h"
+#include "FileChainedLogOut.h"
+
+namespace AsteriskSCF
+{
+
+namespace System
+{
+
+namespace Logging
+{
+
+using namespace AsteriskSCF::System::Configuration::V1;
+using namespace AsteriskSCF::System::Logger::V1;
+
+class FileItemI : public FileItem
+{
+public:
+    FileItemI(const LoggingServerIPtr &server, const std::string &fileName)
+        : mServer(server), mOut(new FileChainedLogOut(fileName))
+    {
+        mServer->addLogOut(mOut);
+    }
+    ~FileItemI()
+    {
+        mServer->removeLogOut(mOut);
+    }
+    LoggingServerIPtr mServer;
+    boost::shared_ptr<ChainedLogOut> mOut;
+};
+
+typedef boost::shared_ptr<FileItemI> FileItemIPtr;
+
+class LoggerGeneralGroupI : public LoggerGeneralGroup
+{
+public:
+    LoggerGeneralGroupI(LoggerGeneralGroupPtr group)
+        : mGroup(group) { }
+    FileItemIPtr mOutputFile;
+    LoggerGeneralGroupPtr mGroup;
+};
+
+typedef boost::shared_ptr<LoggerGeneralGroupI> LoggerGeneralGroupIPtr;
+
+class ConfigurationServiceImpl
+{
+public:
+    ConfigurationServiceImpl(LoggingServerIPtr server)
+        : mServer(server) { }
+    LoggingServerIPtr mServer;
+    LoggerGeneralGroupIPtr mGeneralGroupI;
+};
+
+typedef boost::shared_ptr<ConfigurationServiceImpl> ConfigurationServiceImplPtr;
+
+ConfigurationService::ConfigurationService(LoggingServerIPtr server)
+    : mImpl(new ConfigurationServiceImpl(server)) { }
+
+ConfigurationGroupSeq ConfigurationService::getConfiguration(const ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class visitor : public LoggerConfigurationGroupVisitor
+    {
+    public:
+        visitor(ConfigurationServiceImplPtr impl, ConfigurationGroupSeq &groups)
+            : mImpl(impl), mGroups(groups) { }
+    private:
+        /**
+         * Internal helper function which determines what configuration items should be returned
+       	 */
+       	void insertRequestedConfigurationItems(ConfigurationItemDict& requestedItems,
+       	    ConfigurationItemDict& localItems,
+       	    ConfigurationItemDict& returnedItems)
+       	{
+       	    
+       	    for (ConfigurationItemDict::iterator requestedItem = requestedItems.begin();
+       		 requestedItem != requestedItems.end();
+       		 ++requestedItem)
+       	    {
+                ConfigurationItemDict::iterator localItem = localItems.find((*requestedItem).first);
+       
+       	        if (localItem == localItems.end())
+                {
+                    continue;
+       	        }
+       
+       	        returnedItems.insert(make_pair((*requestedItem).first, (*requestedItem).second));
+       	    }
+       	}
+
+        void visitLoggerGeneralGroup(const LoggerGeneralGroupPtr &group)
+        {
+            if (!mImpl->mGeneralGroupI)
+            {
+                return;
+            }
+
+            LoggerGeneralGroupPtr returnedGroup = new LoggerGeneralGroup();
+            insertRequestedConfigurationItems(group->configurationItems, mImpl->mGeneralGroupI->mGroup->configurationItems, returnedGroup->configurationItems);
+            mGroups.push_back(returnedGroup);
+        }
+
+        ConfigurationServiceImplPtr mImpl;
+        ConfigurationGroupSeq &mGroups;
+    };
+
+    ConfigurationGroupSeq newGroups;
+    LoggerConfigurationGroupVisitorPtr v = new visitor(mImpl, newGroups);
+
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+
+    return newGroups;
+}
+
+ConfigurationGroupSeq ConfigurationService::getConfigurationAll(const ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class visitor : public LoggerConfigurationGroupVisitor
+    {
+    public:
+        visitor(ConfigurationServiceImplPtr impl, ConfigurationGroupSeq &groups)
+            : mImpl(impl), mGroups(groups) { }
+    private:
+        void visitLoggerGeneralGroup(const LoggerGeneralGroupPtr &group)
+        {
+            if (!mImpl->mGeneralGroupI)
+            {
+                return;
+            }
+
+            mGroups.push_back(mImpl->mGeneralGroupI->mGroup);
+        }
+
+        ConfigurationServiceImplPtr mImpl;
+        ConfigurationGroupSeq &mGroups;
+    };
+
+    ConfigurationGroupSeq newGroups;
+    LoggerConfigurationGroupVisitorPtr v = new visitor(mImpl, newGroups);
+    
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+
+    return newGroups;
+}
+
+ConfigurationGroupSeq ConfigurationService::getConfigurationGroups(const Ice::Current&)
+{
+    ConfigurationGroupSeq groups;
+
+    if (mImpl->mGeneralGroupI)
+    {
+        LoggerGeneralGroupPtr general = new LoggerGeneralGroup();
+        groups.push_back(general);
+    }
+
+    return groups;
+}
+
+void ConfigurationService::setConfiguration(const ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class GroupsVisitor : public LoggerConfigurationGroupVisitor
+    {
+    public:
+        GroupsVisitor(ConfigurationServiceImplPtr impl)
+            : mImpl(impl) { }
+    private:
+        /**
+         * Helper function which performs serial number checking of items
+         */
+        void performSerialCheck(ConfigurationItemDict& changedItems, ConfigurationItemDict& localItems)
+        {
+            for (ConfigurationItemDict::iterator item = changedItems.begin();
+                    item != changedItems.end();
+                    ++item)
+   	        {
+                // If serial checking is to be skipped for this item just skip over it
+                if (item->second->serialNumber == -1)
+   	            {
+   	                continue;
+   	            }
+
+   	            ConfigurationItemDict::iterator localItem = localItems.find(item->first);
+
+   	            if (localItem == localItems.end())
+   	            {
+   	                // This is a new item so serial checking does not apply
+   		            continue;
+   	            }
+
+   	            if (item->second->serialNumber < localItem->second->serialNumber)
+                {
+                    /* XXX Need to throw the exception */
+   		        }
+   	        }
+        }
+
+        void visitLoggerGeneralGroup(const LoggerGeneralGroupPtr &group)
+        {
+            if (!mImpl->mGeneralGroupI)
+            {
+                mImpl->mGeneralGroupI.reset(new LoggerGeneralGroupI(new LoggerGeneralGroup));
+            }
+            else
+            {
+                performSerialCheck(group->configurationItems, mImpl->mGeneralGroupI->mGroup->configurationItems);
+            }
+            
+            class GeneralItemsVisitor : public LoggerConfigurationItemVisitor
+            {
+            public:
+                GeneralItemsVisitor(ConfigurationServiceImplPtr impl)
+                    : mImpl(impl) { }
+            private:
+                void visitFileItem(const FileItemPtr &fileItem)
+                {
+                    if (mImpl->mGeneralGroupI->mOutputFile &&
+                            mImpl->mGeneralGroupI->mOutputFile->fileName == fileItem->fileName)
+                    {
+                        // The new configuration has the same file name as
+                        // the old. Don't interrupt things. Just return.
+                        return;
+                    }
+
+                    mImpl->mGeneralGroupI->mOutputFile.reset(new FileItemI(mImpl->mServer, fileItem->fileName));
+                }
+                ConfigurationServiceImplPtr mImpl;
+            };
+
+            LoggerConfigurationItemVisitorPtr generalVisitor = new GeneralItemsVisitor(mImpl);
+
+            for (ConfigurationItemDict::const_iterator item = group->configurationItems.begin();
+                    item != group->configurationItems.end();
+                    ++item)
+            {
+                mImpl->mGeneralGroupI->mGroup->configurationItems.insert(make_pair(item->first, item->second));
+                item->second->visit(generalVisitor);
+            }
+        }
+        ConfigurationServiceImplPtr mImpl;
+    };
+    LoggerConfigurationGroupVisitorPtr v = new GroupsVisitor(mImpl);
+    
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+}
+
+void ConfigurationService::removeConfigurationItems(const ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class GroupsVisitor : public LoggerConfigurationGroupVisitor
+    {
+    public:
+        GroupsVisitor(ConfigurationServiceImplPtr impl)
+            : mImpl(impl) { }
+    private:
+
+        void removeItems(LoggerConfigurationItemVisitor* visitor, ConfigurationItemDict& itemsToRemove,
+            ConfigurationItemDict& localItems)
+        {
+            for (ConfigurationItemDict::const_iterator item = itemsToRemove.begin();
+                 item != itemsToRemove.end();
+                 ++item)
+            {
+                ConfigurationItemDict::iterator localItem = localItems.find(item->first);
+                if (localItem ==  localItems.end())
+                {
+                    continue;
+                }
+                if (visitor != 0)
+                {
+                    item->second->visit(visitor);
+                }
+                localItems.erase(localItem);
+            }
+        }
+
+        void visitLoggerGeneralGroup(const LoggerGeneralGroupPtr &group)
+        {
+            if (!mImpl->mGeneralGroupI)
+            {
+                return;
+            }
+ 
+            class GeneralItemsVisitor : public LoggerConfigurationItemVisitor
+            {
+            public:
+                GeneralItemsVisitor(const LoggerGeneralGroupIPtr &group)
+                    : mGroup(group) { }
+            private:
+                void visitFileItem(const FileItemPtr &fileItem)
+                {
+                    if (mGroup->mOutputFile && mGroup->mOutputFile->fileName == fileItem->fileName)
+                    {
+                        mGroup->mOutputFile.reset();
+                    }
+                }
+                LoggerGeneralGroupIPtr mGroup;
+            } generalVisitor(mImpl->mGeneralGroupI);
+
+            removeItems(&generalVisitor, group->configurationItems, mImpl->mGeneralGroupI->mGroup->configurationItems);
+        }
+        ConfigurationServiceImplPtr &mImpl;
+    };
+
+    LoggerConfigurationGroupVisitorPtr v = new GroupsVisitor(mImpl);
+ 
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+}
+
+void ConfigurationService::removeConfigurationGroups(const ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class visitor : public LoggerConfigurationGroupVisitor
+    {
+    public:
+        visitor(ConfigurationServiceImplPtr &impl)
+            : mImpl(impl) { }
+    private:
+        void visitLoggerGeneralGroup(const LoggerGeneralGroupPtr &group)
+        {
+            mImpl->mGeneralGroupI.reset();
+        }
+        ConfigurationServiceImplPtr mImpl;
+    };
+
+    LoggerConfigurationGroupVisitorPtr v = new visitor(mImpl);
+
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+}
+
+}; //End namespace Logging
+
+}; //End namespace System
+
+}; //End namespace AsteriskSCF
diff --git a/server/src/Configuration.h b/server/src/Configuration.h
new file mode 100644
index 0000000..3b5b8b6
--- /dev/null
+++ b/server/src/Configuration.h
@@ -0,0 +1,66 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#pragma once
+
+#include <Ice/Ice.h>
+
+#include <boost/shared_ptr.hpp>
+
+#include <AsteriskSCF/System/Component/ConfigurationIf.h>
+
+#include "LoggingServer.h"
+#include "LoggingConfigurationIf.h"
+
+namespace AsteriskSCF
+{
+
+namespace System
+{
+
+namespace Logging
+{
+
+/*
+ * Private implementation class for ConfigurationService.
+ */
+class ConfigurationServiceImpl;
+
+/**
+ * Implementation of the configuration service.
+ */
+class ConfigurationService : public AsteriskSCF::System::Configuration::V1::ConfigurationService
+{
+public:
+    ConfigurationService(LoggingServerIPtr server);
+    AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq getConfiguration(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+    AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq getConfigurationAll(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+    AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq getConfigurationGroups(const Ice::Current&);
+    void setConfiguration(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+    void removeConfigurationItems(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+    void removeConfigurationGroups(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+private:
+    /**
+     * Private implementation details.
+     */
+    boost::shared_ptr<ConfigurationServiceImpl> mImpl;
+};
+
+}; //End namespace Logging
+
+}; //End namespace System
+
+}; //End namespace AsteriskSCF

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/logger.git



More information about the asterisk-scf-commits mailing list