[GME-commit] GMESRC/GME/XmlBackEnd CoreXmlFile.cpp,1.3,1.4 CoreXmlFile.h,1.3,1.4

gme-commit at list.isis.vanderbilt.edu gme-commit at list.isis.vanderbilt.edu
Fri Oct 29 11:50:54 CDT 2004


Update of /var/lib/gme/GMESRC/GME/XmlBackEnd
In directory braindrain:/tmp/cvs-serv435

Modified Files:
	CoreXmlFile.cpp CoreXmlFile.h 
Log Message:
no message

CVS User: bogyom

Index: CoreXmlFile.cpp
===================================================================
RCS file: /var/lib/gme/GMESRC/GME/XmlBackEnd/CoreXmlFile.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** CoreXmlFile.cpp	21 Oct 2004 20:51:40 -0000	1.3
--- CoreXmlFile.cpp	29 Oct 2004 15:50:51 -0000	1.4
***************
*** 392,401 ****
  ////////////////////////////////////////////////////////////////////////////////
  
! XmlObject::XmlObject(ICoreMetaObject *metaobject, bool createAllAttributes)
  {
      m_deleted         = false;
      m_modified        = false;
      m_loaded          = createAllAttributes;
! 
      COMTHROW( metaobject->get_MetaID( &m_metaid ) );
      if( m_loaded )
--- 392,401 ----
  ////////////////////////////////////////////////////////////////////////////////
  
! XmlObject::XmlObject(ICoreMetaObject *metaobject, bool createAllAttributes )
  {
      m_deleted         = false;
      m_modified        = false;
      m_loaded          = createAllAttributes;
!     
      COMTHROW( metaobject->get_MetaID( &m_metaid ) );
      if( m_loaded )
***************
*** 404,407 ****
--- 404,409 ----
          createAttributes(metaobject,ATTR_PRIMARY);
      CoCreateGuid(&m_guid);
+ 
+     m_sourceControlInfoRegNode = false;
  }
  
***************
*** 687,695 ****
  		COMRETURN(E_INVALID_USAGE);
  
!     // root's guid chenges evry time the project is modified we should igonre it
      // it casues some meta interpreter problems!
      if( m_metaAttributeId == ATTRID_GUID )
          return S_OK;
  
      // TODO: return with specific error code
      //if( m_openedObject->m_readOnly )
--- 689,714 ----
  		COMRETURN(E_INVALID_USAGE);
  
!     // root's guid changes evry time the project is modified we should igonre it
      // it casues some meta interpreter problems!
      if( m_metaAttributeId == ATTRID_GUID )
          return S_OK;
  
+     // setting root's ATTRID_MDATE to "updatesourcecontrolinfo" means we have to update sourcecontrolinfo
+     // and ignore attribute setting
+     if( m_metaAttributeId == ATTRID_MDATE )
+     {
+         string str;
+         CopyTo(p, str);
+         if( strcmp( str.c_str(), "UpdateSourceControlInfo" ) == 0 )
+         {
+             updateSourceControlInfo();
+             return S_OK;
+         }
+     }
+ 
+     // ignore UpdateSourceControlInfo regnode
+     if( m_openedObject->m_sourceControlInfoRegNode && m_metaAttributeId == ATTRID_REGNODEVALUE)
+         return S_OK;
+ 
      // TODO: return with specific error code
      //if( m_openedObject->m_readOnly )
***************
*** 801,804 ****
--- 820,826 ----
          m_openedObject = obj;
  		*objid = (long)obj;
+ 
+         if( obj->m_metaid==DTID_MODEL || obj->m_metaid==DTID_FOLDER )
+             createSourceControlInfoRegNode( obj );
  	}
  	COMCATCH(;)
***************
*** 1470,1473 ****
--- 1492,1538 ----
  }
  
+ void CCoreXmlFile::createSourceControlInfoRegNode(XmlObject * obj)
+ {
+     ASSERT( obj->m_metaid==DTID_MODEL || obj->m_metaid==DTID_FOLDER );
+ 
+     CComObjPtr<ICoreMetaObject> regNodeMetaObj;
+ 	COMTHROW( m_metaProject->get_Object(DTID_REGNODE, PutOut(regNodeMetaObj)) );
+ 	ASSERT( regNodeMetaObj != NULL );
+ 
+     // create and add new object
+     XmlObject * obj2 = new XmlObject(regNodeMetaObj,true);
+     obj2->m_sourceControlInfoRegNode = true;
+     addObject( obj2 );
+ 
+     // set parent
+     setPointer( obj2, ATTRID_REGNOWNER, obj );
+ 
+     // set attributes
+     AttribMapIter it = obj2->m_attributes.find( ATTRID_NAME );
+     it->second->fromString("SourceControlInfo");
+     it = obj2->m_attributes.find( ATTRID_REGNODEVALUE );
+     it->second->fromString("0");
+     it = obj2->m_attributes.find( ATTRID_REGFLAGS );
+     it->second->fromString("1");
+ }
+ 
+ void CCoreXmlFile::createSourceControlInfoRegNodes()
+ {
+     // collect containers
+     XmlObjVec containers;
+     for( XmlObjVecIter it=m_objects.begin(); it!=m_objects.end(); ++it )
+     {   
+         XmlObject * obj = (*it);
+ 
+         if( obj->m_metaid==DTID_MODEL || obj->m_metaid==DTID_FOLDER )
+             containers.push_back( obj );
+         //if( obj->isContainer() )
+           //  containers.push_back( obj );
+     }
+ 
+     for( it=containers.begin(); it!=containers.end(); ++it )
+         createSourceControlInfoRegNode( *it );
+ }
+ 
  void CCoreXmlFile::getPointer(XmlAttrPointer * attr, VARIANT * p)
  {
***************
*** 1554,1558 ****
              // lehet hogy a containert megiscsak tarolni kene??? ezt at kell gondolni!!!
              containers.insert( container );
!             for(AttribMapIter it=obj->m_attributes.begin(); it!=obj->m_attributes.end(); ++it)
              {
                  if( it->second->getType() == VALTYPE_COLLECTION )
--- 1619,1623 ----
              // lehet hogy a containert megiscsak tarolni kene??? ezt at kell gondolni!!!
              containers.insert( container );
!             for(AttribMapIter it=container->m_attributes.begin(); it!=container->m_attributes.end(); ++it)
              {
                  if( it->second->getType() == VALTYPE_COLLECTION )
***************
*** 1561,1565 ****
                      for( XmlObjSetIter it2=coll->m_children.begin(); it2!=coll->m_children.end(); ++it2 )
                      {
!                         XmlObject * obj2 = (*it2);
                          if( obj2 != NULL )
                              getDependetContainers( obj2, containers, processedObjects );
--- 1626,1630 ----
                      for( XmlObjSetIter it2=coll->m_children.begin(); it2!=coll->m_children.end(); ++it2 )
                      {
!                            XmlObject * obj2 = (*it2);
                          if( obj2 != NULL )
                              getDependetContainers( obj2, containers, processedObjects );
***************
*** 1603,1607 ****
              {
                  fclose(f);
!                 int checkoutState = getCheckOutState( fileName.c_str() );
  
                  if( checkoutState == CS_OTHER_USER )
--- 1668,1672 ----
              {
                  fclose(f);
!                 int checkoutState = getCheckOutStateCC( fileName.c_str() );
  
                  if( checkoutState == CS_OTHER_USER )
***************
*** 1999,2006 ****
  void CCoreXmlFile::writeObject(XmlObject * obj, FILE * file, bool container, const char * prefix)
  {        
!     std::string                          str;
      CComObjPtr<ICoreMetaObject>     metaobject;
      CComBSTR                        metaToken;
  
      COMTHROW( m_metaProject->get_Object( obj->m_metaid, PutOut(metaobject) ) );
      COMTHROW( metaobject->get_Token( &metaToken ) );
--- 2064,2074 ----
  void CCoreXmlFile::writeObject(XmlObject * obj, FILE * file, bool container, const char * prefix)
  {        
!     std::string                     str;
      CComObjPtr<ICoreMetaObject>     metaobject;
      CComBSTR                        metaToken;
  
+     if( obj->m_sourceControlInfoRegNode )
+         return;
+ 
      COMTHROW( m_metaProject->get_Object( obj->m_metaid, PutOut(metaobject) ) );
      COMTHROW( metaobject->get_Token( &metaToken ) );
***************
*** 2274,2278 ****
--- 2342,2352 ----
      _findclose( searchHandle );
  
+     
      resolvePointers( pointers );
+ 
+     
+     createSourceControlInfoRegNodes();
+     updateSourceControlInfo();
+ 
  }
  
***************
*** 2483,2486 ****
--- 2557,2602 ----
      return false;
  }
+ 
+ void CCoreXmlFile::getSSCheckOutUser(XmlObject * obj, string& user)
+ {
+     ASSERT( m_sourceControl == SC_SOURCESAFE );
+     ASSERT( obj->isContainer() );
+ 
+     char buf[300];
+ 
+     string fullPath;
+     getSourceSafePath( obj, fullPath );
+     CComBSTR fullPath2 = fullPath.c_str();
+ 
+     CComObjPtr<IVSSItem> item;
+     COMTHROW( m_vssDatabase->get_VSSItem( fullPath2, false, &(item.p)) );
+     CComObjPtr<IVSSCheckouts> checkouts;
+     COMTHROW( item->get_Checkouts( &(checkouts.p) ));
+     long checkoutNum;
+     COMTHROW( checkouts->get_Count( &checkoutNum ) );
+     if( checkoutNum > 0 )
+     {
+         CComObjPtr<IVSSCheckout> checkout;
+         VARIANT index;
+         index.vt = VT_INT;
+         index.intVal = 1;
+         COMTHROW( checkouts->get_Item(index, &(checkout.p)));
+ 
+         CComBSTR userName;
+         COMTHROW( checkout->get_Username( &userName ));
+ 
+         string name, type;
+         getContainerName( obj, name, type );
+        
+         sprintf( buf, "%S", userName );
+ 
+         user = buf;
+     }
+     else
+     {
+         // not checked out
+         user = "";
+     }
+ }
      
  void CCoreXmlFile::checkOutContainer(XmlObject * obj)
***************
*** 2684,2688 ****
  }
  
! int CCoreXmlFile::getCheckOutState( const char * path )
  {
      // get windows (and clearcase) username
--- 2800,2804 ----
  }
  
! int CCoreXmlFile::getCheckOutStateCC( const char * path )
  {
      // get windows (and clearcase) username
***************
*** 2820,2863 ****
      {
          CFilesInUseDetailsDlg dlg;
- 
          char buf[300];
- 
          XmlObjSet::iterator it;
- 
          for( it=containers.begin(); it!=containers.end(); ++it )
          {
!             string fullPath;
!             getSourceSafePath( *it, fullPath );
!             CComBSTR fullPath2 = fullPath.c_str();
! 
!             CComObjPtr<IVSSItem> item;
!             COMTHROW( m_vssDatabase->get_VSSItem( fullPath2, false, &(item.p)) );
!             CComObjPtr<IVSSCheckouts> checkouts;
!             COMTHROW( item->get_Checkouts( &(checkouts.p) ));
!             long checkoutNum;
!             COMTHROW( checkouts->get_Count( &checkoutNum ) );
!             if( checkoutNum > 0 )
              {
-                 CComObjPtr<IVSSCheckout> checkout;
-                 VARIANT index;
-                 index.vt = VT_INT;
-                 index.intVal = 1;
-                 COMTHROW( checkouts->get_Item(index, &(checkout.p)));
- 
-                 CComBSTR userName;
-                 COMTHROW( checkout->get_Username( &userName ));
- 
                  string name, type;
                  getContainerName( *it, name, type );
! 
!                 //sprintf( buf, "%S\t%s", userName, fullPath.c_str() );
!                 sprintf( buf, "%S\t%s (%s)", userName, name.c_str(), type.c_str() );
! 
                  dlg.m_fileList.push_back( buf );
              }
          }
- 
          dlg.DoModal();
- 
      }
      else 
--- 2936,2954 ----
      {
          CFilesInUseDetailsDlg dlg;
          char buf[300];
          XmlObjSet::iterator it;
          for( it=containers.begin(); it!=containers.end(); ++it )
          {
!             string user;
!             getSSCheckOutUser( *it, user );
!             if( user.size() > 0 )
              {
                  string name, type;
                  getContainerName( *it, name, type );
!                 sprintf( buf, "%s\t%s (%s)", user.c_str(), name.c_str(), type.c_str() );
                  dlg.m_fileList.push_back( buf );
              }
          }
          dlg.DoModal();
      }
      else 
***************
*** 2865,2868 ****
--- 2956,3071 ----
          AfxMessageBox( "No detailed information available." );
      }
+ }
+ 
+ void CCoreXmlFile::setSourceControlInfo( XmlObject * container, const char * scInfo )
+ {
+     ASSERT( container->isContainer() );
+ 
+     // find regnode and set it if found
+     for(AttribMapIter it=container->m_attributes.begin(); it!=container->m_attributes.end(); ++it)
+     {
+         if( it->second->getType() == VALTYPE_COLLECTION )
+         {
+             XmlAttrCollection * coll = (XmlAttrCollection *)it->second;
+             for( XmlObjSetIter it2=coll->m_children.begin(); it2!=coll->m_children.end(); ++it2 )
+             {
+                 XmlObject * obj2 = (*it2);
+                 if( obj2->m_sourceControlInfoRegNode )
+                 {
+                     AttribMapIter it = obj2->m_attributes.find( ATTRID_REGNODEVALUE );
+                     ASSERT( it!=obj2->m_attributes.end() );
+                     it->second->fromString(scInfo);
+                     return;
+                 }
+             }
+         }
+     }
+ }
+ 
+ void CCoreXmlFile::getSourceControlInfo( XmlObject * container, string& scInfo )
+ {
+     ASSERT( container->isContainer() );
+ 
+     scInfo = "";
+ 
+     // find regnode and set it if found
+     for(AttribMapIter it=container->m_attributes.begin(); it!=container->m_attributes.end(); ++it)
+     {
+         if( it->second->getType() == VALTYPE_COLLECTION )
+         {
+             XmlAttrCollection * coll = (XmlAttrCollection *)it->second;
+             for( XmlObjSetIter it2=coll->m_children.begin(); it2!=coll->m_children.end(); ++it2 )
+             {
+                 XmlObject * obj2 = (*it2);
+                 if( obj2->m_sourceControlInfoRegNode )
+                 {
+                     AttribMapIter it = obj2->m_attributes.find( ATTRID_REGNODEVALUE );
+                     ASSERT( it!=obj2->m_attributes.end() );
+                     it->second->toString(scInfo);
+                     return;
+                 }
+             }
+         }
+     }
+ }
+ 
+ void CCoreXmlFile::updateSourceControlInfo( XmlObject * container )
+ {
+     ASSERT( container->isContainer() );
+ 
+     if( m_sourceControl == SC_SOURCESAFE )
+     {
+         string user;
+         getSSCheckOutUser( container, user );
+         if( user.size() == 0 )
+             setSourceControlInfo( container, "GME_SourceControl_State_none" );  // not checked out
+         else if( stricmp( user.c_str(), m_vssUser.c_str() ) == 0 )
+             setSourceControlInfo( container, "GME_SourceControl_State_local" );  // checked out by local user
+         else
+             setSourceControlInfo( container, "GME_SourceControl_State_other" );  // checked out by other user
+     }
+     else if( m_sourceControl == SC_CLEARCASE )
+     {
+         string fileName;
+         getContainerFileName( container, fileName, true );
+         int state = getCheckOutStateCC( fileName.c_str() );
+         if( state == CS_NOT_CHECKEDOUT )
+             setSourceControlInfo( container, "GME_SourceControl_State_none" );
+         else if( state == CS_CURRENT_USER )
+             setSourceControlInfo( container, "GME_SourceControl_State_local" );
+         else
+             setSourceControlInfo( container, "GME_SourceControl_State_other" );
+     }
+ }
+ 
+ void CCoreXmlFile::updateSourceControlInfo()
+ {
+     for( XmlObjVecIter it=m_objects.begin(); it!=m_objects.end(); ++it )
+     {   
+         XmlObject * obj = (*it);
+         if( obj->isContainer() )
+             updateSourceControlInfo( obj );
+     }
+     dumpSourceControlInfo();
+ }
+ 
+ void CCoreXmlFile::dumpSourceControlInfo()
+ {
+     FILE * f = fopen( "c:\\temp\\out.txt", "w" );
+ 
+     for( XmlObjVecIter it=m_objects.begin(); it!=m_objects.end(); ++it )
+     {   
+         XmlObject * obj = (*it);
+         if( obj->isContainer() )
+         {
+             string guid, str;
+             guid2str( obj->m_guid, guid );
+             getSourceControlInfo( obj, str );
+ 
+             fprintf( f, "%s\t%s\n", guid.c_str(), str.c_str() );
+         }
+     }
+ 
+     fclose(f);
  }
  

Index: CoreXmlFile.h
===================================================================
RCS file: /var/lib/gme/GMESRC/GME/XmlBackEnd/CoreXmlFile.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** CoreXmlFile.h	21 Oct 2004 20:51:40 -0000	1.3
--- CoreXmlFile.h	29 Oct 2004 15:50:51 -0000	1.4
***************
*** 46,55 ****
  
  typedef std::set<XmlObject*>                 XmlObjSet;
! typedef XmlObjSet::iterator             XmlObjSetIter;
  typedef std::vector<XmlObject*>              XmlObjVec;
! typedef XmlObjVec::iterator             XmlObjVecIter;
  typedef std::map<metaid_type,attrid_type>    ParentMap;
  typedef std::map<GUID, XmlObject*,GUID_less> GUIDToXmlObjectMap;
! typedef GUIDToXmlObjectMap::iterator    GUIDToXmlObjectMapIter;
  
  
--- 46,55 ----
  
  typedef std::set<XmlObject*>                 XmlObjSet;
! typedef XmlObjSet::iterator                  XmlObjSetIter;
  typedef std::vector<XmlObject*>              XmlObjVec;
! typedef XmlObjVec::iterator                  XmlObjVecIter;
  typedef std::map<metaid_type,attrid_type>    ParentMap;
  typedef std::map<GUID, XmlObject*,GUID_less> GUIDToXmlObjectMap;
! typedef GUIDToXmlObjectMap::iterator         GUIDToXmlObjectMapIter;
  
  
***************
*** 74,78 ****
  
  typedef std::map<attrid_type,XmlAttrBase*>   AttribMap;
! typedef AttribMap::iterator             AttribMapIter;
  
  ////////////////////////////////////////////////////////////////////////////////
--- 74,78 ----
  
  typedef std::map<attrid_type,XmlAttrBase*>   AttribMap;
! typedef AttribMap::iterator                  AttribMapIter;
  
  ////////////////////////////////////////////////////////////////////////////////
***************
*** 208,212 ****
  
  public:
!                 XmlObject           (ICoreMetaObject *metaobject, bool createAllAttributes);
                 ~XmlObject           ();
  
--- 208,212 ----
  
  public:
!                 XmlObject           (ICoreMetaObject *metaobject, bool createAllAttributes );
                 ~XmlObject           ();
  
***************
*** 225,228 ****
--- 225,229 ----
      bool               m_deleted;
      bool               m_modified;
+     bool               m_sourceControlInfoRegNode;  
  
      friend class CCoreXmlFile;
***************
*** 349,354 ****
      void         setPointer             (XmlObject * obj, attrid_type attribId, XmlObject * pointed);
  
-     //void         setPointer             (XmlObject * obj, XmlAttrPointer * attr, VARIANT p)
- 
      void         setPointer             (VARIANT p);
      
--- 350,353 ----
***************
*** 357,360 ****
--- 356,363 ----
      void         resolvePointers        (UnresolvedPointerVec& pointers);
  
+     void         createSourceControlInfoRegNode(XmlObject * obj);
+ 
+     void         createSourceControlInfoRegNodes();
+ 
      // getting connections
      void         getPointer             (XmlAttrPointer * attr, VARIANT * p);
***************
*** 419,422 ****
--- 422,427 ----
      bool         isContinerCheckedOut   (XmlObject * obj);
  
+     void         getSSCheckOutUser      (XmlObject * obj, std::string& user);
+ 
      void         checkOutContainer      (XmlObject * obj);
  
***************
*** 435,439 ****
      bool         isFileCheckedOutCC     ( const char * path );
  
!     int          getCheckOutState       ( const char * path );
  
      void         checkOutFileCC         ( const char * path );
--- 440,444 ----
      bool         isFileCheckedOutCC     ( const char * path );
  
!     int          getCheckOutStateCC     ( const char * path );
  
      void         checkOutFileCC         ( const char * path );
***************
*** 448,451 ****
--- 453,466 ----
  
      void         showUsedFiles          ( XmlObjSet& containers );
+ 
+     void         setSourceControlInfo   ( XmlObject * container, const char * scInfo );
+ 
+     void         getSourceControlInfo   ( XmlObject * container, std::string& scInfo );
+ 
+     void         updateSourceControlInfo( XmlObject * container );
+ 
+     void         updateSourceControlInfo();
+ 
+     void         dumpSourceControlInfo  ();
  
  protected:



More information about the GME-commit mailing list