OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [ecostest/] [common/] [eCosTestPlatform.cpp] - Blame information for rev 856

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000, 2003, 2009 Free Software Foundation, Inc.      
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
//=================================================================
23
//
24
//        eCosTestPlatform.cpp
25
//
26
//        platform information implementation
27
//
28
//=================================================================
29
#include "eCosTestPlatform.h"
30
#include "eCosTestUtils.h"
31
#include "eCosTrace.h"
32
 
33
std::vector<CeCosTestPlatform> CeCosTestPlatform::arPlatforms;
34
 
35
const CeCosTestPlatform *CeCosTestPlatform::Get(LPCTSTR psz)
36
{
37
  for(int i=0;i<(signed)arPlatforms.size();i++){
38
    const CeCosTestPlatform &t=arPlatforms[i];
39
    if(0==_tcsicmp(t.Name(),psz)){
40
      return &t;
41
    }
42
  }
43
  return NULL;
44
}
45
 
46
CeCosTestPlatform::CeCosTestPlatformProperties::CeCosTestPlatformProperties(CeCosTestPlatform *pti)
47
{
48
  Add(_T("platform"),pti->m_strName);
49
  Add(_T("prefix"),  pti->m_strPrefix);
50
  Add(_T("commands"),pti->m_strCommands);
51
  Add(_T("inferior"),pti->m_strInferior);
52
  Add(_T("prompt"),  pti->m_strPrompt);
53
  Add(_T("ServerSideGdb"),pti->m_nServerSideGdb);
54
}
55
 
56
bool CeCosTestPlatform::LoadFromDir(LPCTSTR pszDir)
57
{
58
  bool rc=true;
59
  TRACE(_T("CeCosTestPlatform::LoadFromDir %s\n"),pszDir);
60
  // Find all the files in directory pszDir and load from each of them
61
  TCHAR szOrigDir[PATH_MAX];
62
  _tgetcwd(szOrigDir,sizeof szOrigDir-1);
63
  if(0==_tchdir(pszDir)){
64
    String strFile;
65
    void *pHandle;
66
    for(bool b=CeCosTestUtils::StartSearch(pHandle,strFile);b;b=CeCosTestUtils::NextFile(pHandle,strFile)){
67
      if(CeCosTestUtils::IsFile(strFile)){
68
        CeCosTestPlatform t;
69
        t.m_strName=strFile;
70
        CeCosTestPlatformProperties prop(&t);
71
        if(prop.LoadFromFile(strFile)){
72
          Add(t);
73
        } else {
74
          ERROR(_T("Illegal platform specification in %s%c%s\n"),pszDir,cPathsep,(LPCTSTR)strFile);
75
          rc=false;
76
        }
77
      }
78
    }
79
    CeCosTestUtils::EndSearch(pHandle);
80
  } else {
81
    ERROR(_T("Failed to change to %s from %s\n"),pszDir,szOrigDir);
82
  }
83
  _tchdir(szOrigDir);
84
 
85
  return rc;
86
}
87
 
88
#ifdef _WIN32
89
bool CeCosTestPlatform::SaveToRegistry(HKEY hTopKey,LPCTSTR pszKey)
90
{
91
  // save target info to the registry
92
 
93
  CProperties::CreateKey(pszKey,hTopKey);
94
  HKEY hKey;
95
  bool rc=ERROR_SUCCESS==RegOpenKeyEx (hTopKey, pszKey, 0L, KEY_ALL_ACCESS, &hKey);
96
  if(rc){
97
    for(int i=0;i<(signed)arPlatforms.size();i++){
98
      HKEY hKey2;
99
      DWORD dwDisp;
100
      const CeCosTestPlatform &ti=arPlatforms[i];
101
      rc&=(ERROR_SUCCESS==RegCreateKeyEx(hKey,ti.Name(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey2, &dwDisp));
102
      if(rc){
103
        LPCTSTR pszPrefix=ti.Prefix();
104
        LPCTSTR pszGdb   =ti.GdbCmds();
105
        LPCTSTR pszInferior=ti.Inferior();
106
        LPCTSTR pszPrompt=ti.Prompt();
107
        DWORD dwServerSideGdb=ti.ServerSideGdb()?1l:0l;
108
        rc&=(ERROR_SUCCESS==RegSetValueEx(hKey2,_T("Prefix"),0,REG_SZ,   (CONST BYTE *)pszPrefix,(1+_tcslen(pszPrefix))*sizeof (TCHAR))) &&
109
            (ERROR_SUCCESS==RegSetValueEx(hKey2,_T("Commands"),0,REG_SZ,   (CONST BYTE *)pszGdb,(1+_tcslen(pszGdb))*sizeof (TCHAR))) &&
110
            (ERROR_SUCCESS==RegSetValueEx(hKey2,_T("Inferior"),0,REG_SZ,   (CONST BYTE *)pszInferior,(1+_tcslen(pszInferior))*sizeof (TCHAR))) &&
111
            (ERROR_SUCCESS==RegSetValueEx(hKey2,_T("Prompt"),0,REG_SZ,   (CONST BYTE *)pszPrompt,(1+_tcslen(pszPrompt))*sizeof (TCHAR))) &&
112
            (ERROR_SUCCESS==RegSetValueEx(hKey2,_T("ServerSideGdb"),0,REG_DWORD,   (CONST BYTE *)&dwServerSideGdb,sizeof (DWORD)));
113
      }
114
      RegCloseKey(hKey2);
115
    }
116
    RegCloseKey(hKey);
117
  }
118
  return rc;
119
}
120
 
121
const String CeCosTestPlatform::GetGreatestSubkey (LPCTSTR pszKey)
122
{
123
  String strSubkey;
124
  HKEY hKey;
125
 
126
  if (ERROR_SUCCESS == RegOpenKeyEx (HKEY_LOCAL_MACHINE, pszKey, 0L, KEY_READ, &hKey)) {
127
    DWORD dwIndex = 0;
128
    TCHAR pszBuffer [MAX_PATH + 1];
129
 
130
    while (ERROR_SUCCESS == RegEnumKey (hKey, dwIndex++, (LPTSTR) pszBuffer, sizeof (pszBuffer))) {
131
      if (strSubkey.compare (pszBuffer) < 0) {
132
        strSubkey = pszBuffer;
133
      }
134
    }
135
 
136
    RegCloseKey (hKey);
137
  }
138
 
139
  TRACE (_T("CeCosTestPlatform::GetGreatestSubkey(\"%s\"): %s\n"), pszKey, (LPCTSTR)strSubkey);
140
  return strSubkey;
141
}
142
#endif
143
 
144
bool CeCosTestPlatform::Load()
145
{
146
  TRACE(_T("CeCosTestPlatform::Load\n"));
147
  srand( (unsigned)time( NULL ) );
148
 
149
#ifdef _WIN32
150
 
151
  // get target info from the registry
152
  String strPlatformsKey = _T("Software\\eCos Configuration Tool\\Platforms");
153
//  strPlatformsKey += GetGreatestSubkey (_T("Software\\eCos"));
154
//  strPlatformsKey += _T("\\Platforms");
155
 
156
  HKEY hKey;
157
  bool rc=ERROR_SUCCESS==RegOpenKeyEx (HKEY_CURRENT_USER, strPlatformsKey, 0L, KEY_READ, &hKey);
158
  DWORD dwSubKeys=0;
159
  if(rc){
160
    // Found the given key.
161
    // Subkeys' names are the target image names:
162
    // Subkeys's values are:
163
    //      Prefix  String
164
    //      Type    String 
165
    //      GdbCmd  String [optional]
166
    FILETIME ftLastWriteTime;
167
    DWORD dwMaxSubKeyLen;
168
    if(ERROR_SUCCESS==RegQueryInfoKey(hKey,NULL,NULL,NULL,&dwSubKeys,&dwMaxSubKeyLen,NULL,NULL,NULL,NULL,NULL,NULL)){
169
      TCHAR *szName=new TCHAR[1+dwMaxSubKeyLen];
170
      DWORD dwSizeName=sizeof(TCHAR)*(1+dwMaxSubKeyLen);
171
      for(DWORD dwIndex=0;ERROR_SUCCESS==RegEnumKeyEx(hKey, dwIndex, szName, &dwSizeName, NULL, NULL, NULL, &ftLastWriteTime); dwIndex++){
172
        CeCosTestPlatform t;
173
        if(t.LoadFromRegistry(hKey,szName)){
174
          t.m_strName=szName;
175
          CeCosTestPlatform::Add(t);
176
        }
177
        dwSizeName=sizeof(TCHAR)*(1+dwMaxSubKeyLen);
178
      }
179
      delete [] szName;
180
    }
181
    RegCloseKey(hKey);
182
  }
183
#endif
184
  const String strDir(CeCosTestUtils::HomeFile(_T(".eCosPlatforms")));
185
#ifdef _WIN32
186
  if(!CeCosTestUtils::Exists(strDir)){
187
    return true;
188
  }
189
#endif
190
  LoadFromDir(strDir);
191
  if(0==Count()){
192
    ERROR(_T("Failed to initialize any targets\n"));
193
  }
194
  return true;
195
}
196
 
197
int CeCosTestPlatform::Add(const CeCosTestPlatform &t)
198
{
199
  for(std::vector<CeCosTestPlatform>::iterator it=arPlatforms.begin();it!=arPlatforms.end();){
200
    if(0==_tcsicmp(it->Name(),t.Name())){
201
      // Careful - there's already something here with this name:
202
      ERROR(_T("Warning: duplicate target info %s\n"),it->Name());
203
      it=arPlatforms.erase(it);
204
    } else {
205
      it++;
206
    }
207
  }
208
  arPlatforms.push_back(t);
209
  return arPlatforms.size()-1;
210
}
211
 
212
void CeCosTestPlatform::RemoveAllPlatforms()
213
{
214
  arPlatforms.clear();
215
}
216
 
217
bool CeCosTestPlatform::LoadFromCommandString(LPCTSTR psz)
218
{
219
  CeCosTestPlatformProperties prop(this);
220
  return prop.LoadFromCommandString(psz);
221
}
222
 
223
#ifdef _WIN32
224
bool CeCosTestPlatform::LoadFromRegistry(HKEY hKey,LPCTSTR pszKey)
225
{
226
  CeCosTestPlatformProperties prop(this);
227
  return prop.LoadFromRegistry(hKey,pszKey);
228
}
229
#endif
230
 
231
bool CeCosTestPlatform::Save()
232
{
233
  const String strDir(CeCosTestUtils::HomeFile(_T(".eCosPlatforms")));
234
#ifdef _WIN32
235
  if(!CeCosTestUtils::Exists(strDir)){
236
    String strPlatformsKey = _T("Software\\eCos Configuration Tool\\Platforms");
237
//    strPlatformsKey += GetGreatestSubkey (_T("Software\\eCos"));
238
//    strPlatformsKey += _T("\\Platforms");
239
 
240
    return SaveToRegistry(HKEY_CURRENT_USER,strPlatformsKey);
241
  }
242
#endif
243
  return SaveToDir(strDir);
244
}
245
 
246
bool CeCosTestPlatform::SaveToDir (LPCTSTR pszDir)
247
{
248
  bool rc=false;
249
  void *pHandle;
250
  TCHAR szOrigDir[256];
251
  _tgetcwd(szOrigDir,sizeof szOrigDir-1);
252
  if(0==_tchdir(pszDir)){
253
    // Delete all the files under directory "pszDir"
254
    String strFile;
255
    for(bool b=CeCosTestUtils::StartSearch(pHandle,strFile);b;b=CeCosTestUtils::NextFile(pHandle,strFile)){
256
      if(CeCosTestUtils::IsFile(strFile)){
257
        _tunlink(strFile);
258
      }
259
    }
260
    CeCosTestUtils::EndSearch(pHandle);
261
    rc=true;
262
    // Rewrite the files
263
    for(int i=0;i<(signed)arPlatforms.size();i++){
264
      CeCosTestPlatform &t=arPlatforms[i];
265
      CeCosTestPlatformProperties prop(&t);
266
      rc&=prop.SaveToFile(t.Name());
267
    }
268
  } else {
269
    ERROR(_T("Failed to change to %s from %s\n"),pszDir,szOrigDir);
270
  }
271
 
272
  return rc;
273
}
274
 
275
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.