00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifdef WINDOWS
00019
00020
00021 #include "stdafx.h"
00022 #endif
00023
00024 #include <stdio.h>
00025
00026 #include "RioInterface.h"
00027
00028 #include "RioError.h"
00029 #include "ObjectManager.h"
00030 #include "SessionManager.h"
00031
00032
00033
00034 CRioDirectory::CRioDirectory()
00035 {
00036 m_ObjectManager = 0;
00037 m_TCPconnection = 0;
00038 m_ObjectHandle.Version = -1;
00039 m_ObjectHandle.Index = -1;
00040 m_opened = false;
00041 }
00042
00043 CRioDirectory::~CRioDirectory()
00044 {
00045 if(m_opened)
00046 {
00047 Close();
00048 }
00049 }
00050
00051 RioResult CRioDirectory::FirstObject (char* DirectoryName,
00052 const int BufferSize,
00053 char* ObjectName,
00054 int* IsDirectory,
00055 CRioSession *RioSession)
00056 {
00057
00058 RioSessionId SessionId;
00059
00060
00061 if(m_opened)
00062 {
00063 return ERROR_RIOOBJECT + ERROR_OBJECT_ALREADY_OPENED;
00064 }
00065
00066 HRESULT hResult;
00067 hResult = RioSession->GetId(&SessionId);
00068 if(FAILED(hResult))
00069 {
00070
00071
00072 return hResult;
00073 }
00074
00075
00076 m_TCPconnection = RioSession->m_TCPconnection;
00077
00078
00079 m_ObjectManager = new CObjectManager(m_TCPconnection);
00080
00081
00082 CSessionManager SessionManager(m_TCPconnection);
00083
00084 hResult = SessionManager.FirstObject(SessionId,
00085 (signed char*)DirectoryName,
00086 &m_ObjectHandle,
00087 IsDirectory,
00088 BufferSize,
00089 (signed char*)ObjectName);
00090 if(FAILED(hResult))
00091 {
00092 m_ObjectHandle.Version = -1;
00093 m_ObjectHandle.Index = -1;
00094 FreeMembers();
00095 return hResult;
00096 }
00097
00098
00099 m_opened = true;
00100
00101 return S_OK;
00102 }
00103
00104
00105 RioResult CRioDirectory::Close()
00106 {
00107
00108
00109 if(!m_opened)
00110 {
00111 return ERROR_RIOOBJECT + ERROR_OBJECT_NOT_OPENED;
00112 }
00113
00114
00115 FreeMembers();
00116
00117 m_opened = false;
00118
00119 return S_OK;
00120 }
00121
00122
00123 RioResult CRioDirectory::NextObject(const int BufferSize,
00124 char* ObjectName,
00125 int* IsDirectory)
00126 {
00127
00128 if(!m_opened)
00129 {
00130 return ERROR_RIOOBJECT + ERROR_OBJECT_NOT_OPENED;
00131 }
00132
00133 HRESULT hResult;
00134
00135
00136 hResult = m_ObjectManager->NextObject(m_ObjectHandle,
00137 IsDirectory,
00138 BufferSize,
00139 (signed char*) ObjectName);
00140
00141
00142 return hResult;
00143
00144 }
00145
00146
00147 void CRioDirectory::FreeMembers()
00148 {
00149 if(m_ObjectHandle.Index != -1)
00150 {
00151 m_ObjectManager->Close(m_ObjectHandle);
00152 m_ObjectHandle.Version = -1;
00153 m_ObjectHandle.Index = -1;
00154 }
00155
00156 if(m_TCPconnection !=0)
00157 {
00158 m_TCPconnection = 0;
00159 }
00160
00161 if(m_ObjectManager != 0)
00162 {
00163 delete m_ObjectManager;
00164 m_ObjectManager = 0;
00165 }
00166
00167 }
00168