TekStd.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Kevin McBride                                   *
00003  *   kevin@planetsaphire.com                                               *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Library General Public License as       *
00007  *   published by the Free Software Foundation; either version 2 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU Library General Public     *
00016  *   License along with this program; if not, write to the                 *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #define     LIBTEKLTI_EXPORT  (0)
00022 //#define   TEKSTD_INTERNAL   (1)
00023 
00024 #ifndef     _cplusplus
00025 #define     _cplusplus  (0)
00026 #endif      /* _cplusplus */
00027 
00028 #include "teklti.h"
00029 
00030 #ifndef     NULLTEST
00031 #define     NULLTEST    (0)
00032 #endif      /* not NULLTEST */
00033 
00034 
00035 MKTEKUUID(UTekStd, "567de9ac-d51c-11d9-871d-000bdbc434d9")
00036 MKTEKDEBUGSTRING(DBTekStd, "TekStd")
00037 
00038 
00042 TekStd::TekStd()
00043 {
00044       TEKSTD_IMPLEMENT_BEGIN
00045       TEKSTD_IMPLEMENT_ENDVARS
00046 }
00047 
00051 TekStd::~TekStd()
00052 {
00053       TEKSTD_IMPLEMENT_FREE
00054 }
00055 
00056 //#if NULLTEST != 0
00057 
00058 //TEKSTD_SOURCE_FUNC(TekStd)
00059 
00063 unsigned int TekStd::AddRef()
00064 {
00065       /* Add a reference to the instance. */
00066       __instancecount++;
00067       /* Return reference count to the caller. */
00068       return __instancecount;
00069 }
00070 
00090 TEKERR TekStd::CheckFor(
00091       const uuid_t * UUIDArray,
00092       size_t UUIDArraySize,
00093       unsigned short Flags,
00094       void ** RetVal,
00095       unsigned int ** RefCountPtrRet
00096 )
00097 {
00098       TEKERR result; /* Used to prepare return value. */
00099       size_t i; /* Used for enumerating UUIDArray. */
00100       size_t j; /* Used for enumerating this->__uuidarray. */
00101 
00102 #ifndef     NO_SIZE_T_CHECKS
00103       if ( UUIDArray == NULL )
00104       {
00105 #ifdef      DEBUG_USE_FERROR
00106             fprintf(
00107                   stderr,
00108                   "POTENTIAL SEGFAULT in interface %s, function CheckFor(): UUIDArray is null!\n",
00109                   TEKDEBUGSTRING(DBTekStd)
00110             );
00111 #endif      /* DEBUG_USE_FERROR */
00112             return TEKERR_POINTER;
00113       }
00114       
00115       if ( Flags )
00116       {
00117             if ( RetVal == NULL )
00118             {
00119 #ifdef      DEBUG_USE_FERROR
00120             fprintf(
00121                   stderr,
00122                   "POTENTIAL SEGFAULT in interface %s, function CheckFor(): RetVal is null!\n",
00123                   TEKDEBUGSTRING(DBTekStd)
00124             );
00125 #endif      /* DEBUG_USE_FERROR */
00126             return TEKERR_POINTER;
00127             }
00128       }
00129 #endif      /* NO_SIZE_T_CHECKS */
00130 
00131       for ( i=0; i < UUIDArraySize; i++ )
00132       {
00133             /*
00134               Check our private UUID array to see if UUIDArray[i]
00135               is supported by this instance.
00136             */
00137             for ( j=0; j < this->__uuidarraycount; j++ )
00138                   if ( uuid_compare(this->__uuidarray[j], UUIDArray[i]) == 0 )
00139                         goto FoundUUID; /* UUIDArray[i] is supported. */
00140 
00141             /* We get here if UUIDArray[i] was not supported. */
00142             /* Increment 'i' to help caller make debugging output. */
00143             i++;
00144             /* Set upper 16 bits to failing UUIDArray element. */
00145             result = i << (8 * sizeof(short));
00146             /* Set lower 16 bits to TEKERR_NOTIMPL. */
00147             result |= TEKERR_NOTIMPL;
00148             /* Return the 'result' value to caller. */
00149             return result;
00150 FoundUUID:
00151             ;
00152       }
00153 
00154       /* We get here if the checks passed. */
00155       /* If Flags is set to 1, we are to add a reference and set RetVal. */
00156       if ( Flags )
00157       {
00158             /* Add a reference to ourselves. */
00159             this->AddRef();
00160             /* Set RetVal to ourselves. */
00161             *RetVal = this;
00162       }
00163 
00164       /* Return to caller with TEKERR_OK status.  That's all folks. */
00165       return TEKERR_OK;
00166 }
00167 
00171 unsigned int TekStd::Release()
00172 {
00173       /* Decrement reference count. */
00174       __instancecount--;
00175 
00176       /* If instancecount is now zero, we need to delete ourselves. */
00177       if ( __instancecount == 0 )
00178       {
00179             /* Delete ourselves. */
00180             delete this;
00181             /* Return zero to indicate "we no longer exist!" */
00182             return 0;
00183       }
00184 
00185       /* Return reference count to caller. */
00186       return __instancecount;
00187 }
00188 
00189 TEKERR TekStd::CallFunc(
00190       const uchar_t * FuncName,
00191       void * RetVal,
00192       unsigned short ParamsCount,
00193       void ** Params
00194 )
00195 {
00196       return TEKERR_NOTIMPL;
00197 }
00198 
00199 //#endif    /* NULL != 0 */
00200 
SourceForge.net Logo  Technical Library Template Interface Project Page