Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

l1394_csrdirectory.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           l1394csrdirectory.cpp  -  description
00003                              -------------------
00004     begin                : Fri Oct 27 2000
00005     copyright            : (C) 2000-2004 by Michael Repplinger
00006     email                : repplinger@cs.uni-sb.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "l1394_csrdirectory.h"
00019 
00020 using namespace std;
00021 // node
00022 namespace L1394{
00023 namespace internal{
00024 const char* DNode::nodeType[] =
00025 {
00026   "immediate",
00027   "offset",
00028   "leaf",
00029   "directory"
00030 };
00031 
00032 const char *DNode::keyValue[] =
00033 {
00034   "CsrDirectory",
00035   "Descriptor",
00036   "Bus_Dependent_Info",
00037   "Vendor",
00038   "Hardware_Version",
00039   "<reserved>",
00040   "<reserved>",
00041   "Module",
00042   "<reserved>",
00043   "<reserved>",
00044   "<reserved>",
00045   "<reserved>",
00046   "Node_Capabilities",
00047   "EUI_64",
00048   "<reserved>",
00049   "<reserved>",
00050   "<reserved>",
00051   "Unit",
00052   "Specifier_ID",
00053   "Version",
00054   "Dependent_Info",
00055   "Unit_Location",
00056   "<reserved>",
00057   "Model",
00058   "Instance",
00059   "Keyword",
00060   "Feature",
00061   "Extended_ROM",
00062   "Extended_Key_Specifier_ID",
00063   "Extended_Key",
00064   "Extended_Data",
00065   "Modifiable_Descriptor",
00066   "Directory_ID",
00067   "<reserved>",
00068   "<reserved>",
00069   "<reserved>",
00070   "<reserved>",
00071   "<reserved>",
00072   "<reserved>",
00073   "<reserved>",
00074   "<reserved>",
00075   "<reserved>",
00076   "<reserved>",
00077   "<reserved>",
00078   "<reserved>",
00079   "<reserved>",
00080   "<reserved>",
00081   "<reserved>",
00082   "<reserved>"
00083 };
00084 
00085 
00086 
00087 DNode::DNode()
00088 {
00089   leafInfo = NULL;
00090   type = 0;
00091 }
00092 
00093 DNode::DNode(int t, CsrDirectory *subdir)
00094 {
00095   leafInfo  = NULL;
00096   subDir    = subdir;
00097   type      = t;
00098 }
00099 
00100 DNode::DNode(int t, QArray *q)
00101 {
00102   type      = t;
00103   subDir    = NULL;
00104   leafInfo  = q;
00105 }
00106 
00107 DNode::~DNode()
00108 {
00109   delete leafInfo;
00110   if (subDir != NULL)
00111   delete subDir;
00112 }
00113 
00114 
00115 void DNode::print()
00116 {
00117   int key_type  = 0;
00118   key_type      = type>>6 ;
00119 
00120   switch(key_type)
00121   {
00122     case 0 : //cout << "Immediate value : " << endl ;
00123              if (leafInfo != NULL) cout << *leafInfo << endl;
00124              break;
00125     case 1 : //cout << "It's an offset value : " << endl;
00126              if (leafInfo != NULL) cout << *leafInfo << endl;
00127              break;
00128     case 2 : //cout << "It's a leaf : " << endl;
00129              if (leafInfo != NULL) cout << *leafInfo << endl;
00130              break;
00131     case 3 : //cout << "It's a Subdirectory : " << *leafInfo << endl;
00132              if (subDir != NULL) subDir->print();
00133              break;
00134   }
00135 }
00136 
00137 
00138 
00139 CsrDirectory::~CsrDirectory()
00140 {
00141   for (int i = 0; i < max_count; i++)
00142     delete root_directory[i];
00143 
00144 }
00145 
00146 
00147 CsrDirectory::CsrDirectory(int i,CsrDirectory *parent)
00148 {
00149   count            = 0;
00150   max_count        = i;
00151   root_directory  = new DNode*[max_count];
00152 
00153   for (int j = 0; j< max_count;j++)
00154     root_directory[j] = NULL;
00155 
00156   this->parent    = parent;
00157 }
00158 
00159 CsrDirectory *CsrDirectory::findSubDir(int key_id, CsrDirectory *startDirectory)
00160 {
00161   CsrDirectory *tmpDirectory, *responseDirectory;
00162 
00163   int tmp            = 0;
00164   responseDirectory = NULL;
00165   tmpDirectory      = startDirectory;
00166 
00167   for  (int i = 0; i < tmpDirectory->getLength(); i++)
00168     {
00169       tmp = (tmpDirectory->getDNode(i)->getType()) & 0x3F;
00170 
00171       if (tmp == key_id & tmpDirectory->getDNode(i)->getSubDir() != NULL)
00172         {
00173           responseDirectory = tmpDirectory->getDNode(i)->getSubDir();
00174           //cout << "FOUND" <<endl;
00175           return responseDirectory;
00176         }
00177       if (tmp != key_id & tmpDirectory->getDNode(i)->getSubDir() != NULL)
00178           responseDirectory = findSubDir(key_id, tmpDirectory->getDNode(i)->getSubDir());
00179     }
00180   return NULL;
00181 }
00182 
00183 
00184 DNode *CsrDirectory::findNode(int key_id, CsrDirectory *startDirectory)
00185 {
00186 //init values
00187   DNode *responseLeaf;
00188   int tmp        = 0;
00189   int key        = 0;
00190   responseLeaf  = NULL;
00191 
00192 //start
00193   if (startDirectory != NULL)
00194     for  (int i = 0; i < startDirectory->getLength(); i++)
00195     {
00196 
00197       tmp = (startDirectory->getDNode(i)->getType()) & 0x3F;
00198       key = (startDirectory->getDNode(i)->getType()) >> 6;
00199 
00200       if (tmp == key_id & key != 3) return startDirectory->getDNode(i);
00201 
00202 // if DNode is a subdir
00203       if (key == 3)
00204         {
00205           responseLeaf = findNode(key_id, startDirectory->getDNode(i)->getSubDir());
00206           if (responseLeaf != NULL) return responseLeaf;
00207         }
00208     }
00209 //  else cout << "(Sub-)Directory doesn't exist "<< endl; //exception ?!?
00210   return NULL;
00211 }
00212 
00213 
00214 }
00215 }

Generated on Wed Aug 24 00:36:40 2005 for L1394 by doxygen 1.4.2
L1394 library (NMM) grahics.cs.uni-sb.de/~repplix/l1394_home/