DumontEXE 0.0.1
cmcApplications.cpp
00001 /* ***************************************************************************
00002 **
00003 ** Copyright (C) 2007 Lorimark Solutions, LLC. All rights reserved.
00004 **
00005 ** This file is part of the DumontEXE Scripting Extension Kit
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://dumont.showoff-db.org/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://dumont.showoff-db.org/licensing.html 
00017 ** or contact the sales department at sales@lorimarksolutions.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ** author: Mark Petryk ~ Lorimark Solutions, LLC
00023 ** **************************************************************************/
00024 
00025 #include "cmcApplications.h"
00026 #include "cmcApplication.h"
00027 #include <QTimer>
00028 #include <QThread>
00029 #include <QApplication>
00030 
00031 #include "cmcError.h"
00032 
00033 namespace cmcDatabaseApi {
00034 
00035 cmcApplications::cmcApplications( const cmcApplications & copy ):
00036   cmcObjects( copy )
00037 {
00038 }
00039 
00040 cmcApplications::cmcApplications( cmcObject * parent ):
00041   cmcObjects( parent )
00042 {
00043   setObjectName("Applications");
00044 
00045 //  TRACE_FUNCTION
00046 }
00047 
00048 cmcApplications::~cmcApplications()
00049 {
00050 //  TRACE_FUNCTION
00051 }
00052 
00053 void cmcApplications::checkApps(void)
00054 {
00055   QList<cmcApplication*> apps = findChildren<cmcApplication*>();
00056 
00057   for( int i = 0; i < apps.count(); i++ )
00058   {
00059     if( !apps.at(i)-> sameDatabase() )
00060     {
00061       qDebug( "removing %s", qPrintable(apps.at(i)-> applicationName()) );
00062       delete apps.at(i);
00063     }
00064   }
00065 }
00066 
00067 cmcApplication * cmcApplications::application( long index )
00068 {
00069   QList<cmcApplication*> children = findChildren<cmcApplication*>();
00070 
00071   return( children.at(index) );
00072 }
00073 
00074 cmcApplication * cmcApplications::application( const QString & applicationName )
00075 {
00076   cmcApplication * retVal = qobject_cast<cmcApplication*>(cmcObjects::get(applicationName));
00077 
00078   if( retVal )
00079   {
00080     if( !retVal-> sameDatabase() )
00081     {
00082       delete retVal;
00083       retVal = NULL;
00084     }
00085   }
00086 
00087   return( retVal );
00088 
00089 }
00090 
00091 long cmcApplications::add( IDispatch * dispatch, const QString & dumontCategory )
00092 {
00093 //  TRACE_FUNCTION
00094 
00095   /*
00096   ** Wrap the application object.  Give it, initially, no parent, so that
00097   **  it does not attach itself to the Applications object.  We can, then,
00098   **  search the Applications object to see if this one is already registered.
00099   **
00100   */
00101   cmcApplication * app = new cmcApplication( dispatch, dumontCategory );
00102 
00103   /*
00104   ** See if it already exists as a child of us.
00105   **
00106   */
00107   if( !findChild<cmcApplication*>( app-> applicationName() ) )
00108   {
00109     /*
00110     ** Reparent the Application object to us.  First off, this will prevent
00111     **  vbScript from deleting the application object, because it has a parent,
00112     **  and secondly, it will allow us to find it again in future requests.
00113     **  This is our version of a running-object-table.
00114     **
00115     */
00116     app-> setParent( this );
00117 
00118     emit( updated() );
00119 
00120   }
00121   else
00122   {
00123     /*
00124     ** If it does exist thn we delete our wrapper since we're not using it anymore.
00125     **
00126     */
00127     delete app;
00128 
00129   }
00130 
00131 //  TRACE_FUNCTION
00132 
00133   /*
00134   ** Return the new count
00135   **
00136   */
00137   return( findChildren<cmcApplication*>().count() );
00138 
00139 } // endlong cmcApplications::add( IDispatch * dispatch )
00140 
00141 
00142 
00143 long cmcApplications::remove( const QString & applicationName )
00144 {
00145   /*
00146   ** Try to get a handle on the requested database.
00147   **
00148   */
00149   cmcApplication * app = findChild<cmcApplication*>( applicationName );
00150 
00151   /*
00152   ** If we got one then delete it.
00153   **
00154   */
00155   if( app )
00156   {
00157     delete app;
00158 
00159     emit( updated() );
00160   }
00161 
00162   /*
00163   ** Return the new registered application count.
00164   **
00165   */
00166   return( findChildren<cmcApplication*>().count() );
00167 
00168 }
00169 
00170 long cmcApplications::remove( IDispatch * dispatch )
00171 {
00172   cmcApplication app(dispatch);
00173 
00174   remove( app.applicationName() );
00175 
00176   return( findChildren<cmcApplication*>().count() );
00177 
00178 }
00179 
00180 
00181 } // endnamespace cmcDatabaseApi
00182 
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties




~ ~ ~ ~ ~ ~
Source Code without Comments is like a Cranberry Garland
without the berries. Comment your Code!
 
Commence Database User Support Group Forum
http://newsgroup.showoff-db.org/
~ ~ ~ ~ ~ ~
Author: Mark Petryk
Lorimark Solutions, LLC
mark@lorimarksolutions.com