File: MachineProfile.code

package info (click to toggle)
paraview 4.1.0%2Bdfsg%2B1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 278,136 kB
  • ctags: 340,527
  • sloc: cpp: 2,314,053; ansic: 817,139; python: 245,770; xml: 68,996; tcl: 48,285; fortran: 39,116; yacc: 5,713; java: 3,827; perl: 3,108; sh: 2,045; lex: 1,809; makefile: 935; asm: 471; pascal: 228
file content (506 lines) | stat: -rw-r--r-- 16,507 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
Initialization: userName
    userName = defaultUserName;

Function: defaultUserName
Declaration: static std::string defaultUserName;
Definition:
std::string MachineProfile::defaultUserName("notset");

Function: SplitHostPattern
Declaration: static std::vector<std::string> SplitHostPattern(const std::string &host);
Definition:
// ****************************************************************************
//  Method:  SplitHostPattern
//
//  Purpose:
//    Returns the host name pattern split into strings by whitespace or commas.
//
//  Programmer:  Jeremy Meredith
//  Creation:    February 13, 2002
//
// ****************************************************************************
std::vector<std::string>
MachineProfile::SplitHostPattern(const std::string &host)
{
    std::vector<std::string> vec;
    std::string              name = "";

    for (size_t i=0; i<host.length(); i++)
    {
        if (host[i] == ' '  || host[i] == '\t' || host[i] == ',')
        {
            if (!name.empty())
            {
                vec.push_back(name);
                name = "";
            }
            continue;
        }
        else
        {
            name += host[i];
        }
    }
    if (!name.empty())
    {
        vec.push_back(name);
        name = "";
    }

    return vec;
}

Function: ProfileMatchesHost
Declaration: bool ProfileMatchesHost(const std::string&) const;
Definition:
// ****************************************************************************
//  Method:  ProfileMatchesHost
//
//  Purpose:
//    True if a hostname matches the host name pattern in the profile.
//
//  Arguments:
//    h          the hostname to compare with this profile
//
//  Programmer:  Jeremy Meredith
//  Creation:    February 13, 2002
//
//  Modifications:
//    Jeremy Meredith, Mon Apr 14 10:06:34 PDT 2003
//    Added matching of host aliases.
//
// ****************************************************************************
bool
MachineProfile::ProfileMatchesHost(const std::string &h) const
{
    std::vector<std::string> patterns = SplitHostPattern(host);
    bool match = false;
    size_t i;

    // Try to match the actual host name
    for (i = 0; i < patterns.size() && !match; i++)
    {
         match = WildcardStringMatch(patterns[i], h);
    }

    // Now match any aliases
    std::vector<std::string> aliases = SplitHostPattern(hostAliases);
    for (i = 0; i < aliases.size() && !match; i++)
    {
         match = WildcardStringMatch(aliases[i], h);
    }

    return match;
}

Function: GetShortHostname
Declaration: std::string GetShortHostname() const;
Definition:
// ****************************************************************************
//  Method:  GetShortHostname
//
//  Purpose:
//    Returns a shortened version of the hostname.
//
//  Programmer:  Jeremy Meredith
//  Creation:    February 13, 2002
//
// ****************************************************************************
std::string
MachineProfile::GetShortHostname() const
{
    return GetShortHostname(host);
}

Function: GetShortHostname_static
Declaration: static std::string GetShortHostname(const std::string &host);
Definition:
// ****************************************************************************
//  Method:  GetShortHostname
//
//  Purpose:
//    Returns a shortened version of the hostname.
//
//  Programmer:  Jeremy Meredith
//  Creation:    February 13, 2002
//
//  Modifications:
//    Jeremy Meredith, Mon Apr 14 14:35:07 PDT 2003
//    Added ability to append a common suffix from patterns.
//
//    Jeremy Meredith, Fri Nov 14 10:37:59 PST 2003
//    Removed the suffix for now, and stop at the first dot.
//
// ****************************************************************************
std::string
MachineProfile::GetShortHostname(const std::string &host)
{
    std::vector<std::string> patterns = SplitHostPattern(host);
    std::string              prefix = "";
    std::string              suffix = "";
    std::string              shortname;

    if (patterns.empty())
        return "";

    // find the minimum length of any string
    size_t l = patterns[0].length();
    for (size_t i = 1; i < patterns.size(); i++)
    {
        if (patterns[i].length() < l)
            l = patterns[i].length();
    }

    // find a common prefix
    for (size_t p = 0; p < l; p++)
    {
        char c = patterns[0][p];
        for (size_t i = 1; i < patterns.size() && c != '\0'; i++)
        {
            if (patterns[i][p] != c)
                c = '\0';
        }
        if (c=='\0' || c=='.')
            break;
        if (c != '*' && c != '?')
            prefix += c;
    }

    // find a common suffix, too
    for (size_t s = 0; s < l - prefix.length() - 1 && patterns.size() > 1; s++)
    {
        char c = patterns[0][l-1-s];
        for (size_t i = 1; i < patterns.size() && c != '\0'; i++)
        {
            if (patterns[i][l-1-s] != c)
                c = '\0';
        }
        if (!c)
            break;
        if (c != '*' && c != '?')
            suffix = c + suffix;
    }

    // combine the short name
    //shortname = prefix + suffix;
    shortname = prefix;
    if (prefix.empty())
        return patterns[0];
    else
        return shortname;
}

Function: GetDefaultUserName_static
Declaration: static const std::string &GetDefaultUserName();
Definition:
// ****************************************************************************
//  Method:  GetDefaultUserName
//
//  Purpose:
//    Returns the default user name.
//
//  Programmer:  Brad Whitlock
//  Creation:    Thu Apr 11 15:13:46 PST 2002
//
// ****************************************************************************

const std::string &
MachineProfile::GetDefaultUserName()
{
    return defaultUserName;
}

Function: SetDefaultUserName_static
Declaration: static void SetDefaultUserName(const std::string &n);
Definition:
// ****************************************************************************
//  Method:  SetDefaultUserName
//
//  Purpose:
//    Returns the default user name.
//
//  Programmer:  Brad Whitlock
//  Creation:    Thu Apr 11 15:13:46 PST 2002
//
// ****************************************************************************

void
MachineProfile::SetDefaultUserName(const std::string &n)
{
    defaultUserName = n;
}

Function: GetActiveLaunchProfile
Declaration: LaunchProfile *GetActiveLaunchProfile() const;
Definition:
LaunchProfile *
MachineProfile::GetActiveLaunchProfile() const
{
    if (activeProfile<0 || activeProfile>=launchProfiles.size())
        return NULL;

    return (LaunchProfile*)launchProfiles[activeProfile];
}

Function: SetFromNode
Declaration: bool SetFromNode(DataNode *parentNode);
Definition:
// ****************************************************************************
// Method: MachineProfile::SetFromNode
//
// Purpose: 
//   This method sets attributes in this object from values in a DataNode representation of the object.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   Jeremy Meredith, Wed Apr 28 17:26:30 EDT 2010
//   For the launch profiles, override old values instead of clearing them.
//   
// ****************************************************************************

void
MachineProfile::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("MachineProfile");
    if(searchNode == 0)
        return;

    DataNode *node;
    DataNode **children;
    if((node = searchNode->GetNode("host")) != 0)
        SetHost(node->AsString());
    if((node = searchNode->GetNode("userName")) != 0)
        SetUserName(node->AsString());
    if((node = searchNode->GetNode("hostAliases")) != 0)
        SetHostAliases(node->AsString());
    if((node = searchNode->GetNode("hostNickname")) != 0)
        SetHostNickname(node->AsString());
    if((node = searchNode->GetNode("directory")) != 0)
        SetDirectory(node->AsString());
    if((node = searchNode->GetNode("shareOneBatchJob")) != 0)
        SetShareOneBatchJob(node->AsBool());
    if((node = searchNode->GetNode("sshPortSpecified")) != 0)
        SetSshPortSpecified(node->AsBool());
    if((node = searchNode->GetNode("sshPort")) != 0)
        SetSshPort(node->AsInt());
    if((node = searchNode->GetNode("activeProfile")) != 0)
        SetActiveProfile(node->AsInt());
    if((node = searchNode->GetNode("clientHostDetermination")) != 0)
    {
        // Allow enums to be int or string in the config file
        if(node->GetNodeType() == INT_NODE)
        {
            int ival = node->AsInt();
            if(ival >= 0 && ival < 3)
                SetClientHostDetermination(ClientHostDetermination(ival));
        }
        else if(node->GetNodeType() == STRING_NODE)
        {
            ClientHostDetermination value;
            if(ClientHostDetermination_FromString(node->AsString(), value))
                SetClientHostDetermination(value);
        }
    }
    if((node = searchNode->GetNode("manualClientHostName")) != 0)
        SetManualClientHostName(node->AsString());
    if((node = searchNode->GetNode("tunnelSSH")) != 0)
        SetTunnelSSH(node->AsBool());

    // Go through all of the children 
    children = searchNode->GetChildren();
    if(children != 0)
    {
        for(int i = 0; i < searchNode->GetNumChildren(); ++i)
        {
            if(children[i]->GetKey() == std::string("LaunchProfile"))
            {
                DataNode *nameNode = children[i]->GetNode("profileName");
                if (!nameNode)
                {
                    // we don't have a name for this launch profile, so we
                    // don't know what to do with it; skip it
                    continue;
                }
                std::string name = nameNode->AsString();
                bool found = false;
                for (int j=0; j<GetNumLaunchProfiles(); j++)
                {
                    LaunchProfile &lp = GetLaunchProfiles(j);
                    if (lp.GetProfileName() == name)
                    {
                        // it matches one already existing...
                        // override any old values with the new ones
                        lp.SetFromNode(children[i]);
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    // didn't find a pre-existing launch profile with 
                    // the same name, so just add it to the list.
                    LaunchProfile temp;
                    temp.SetFromNode(children[i]);
                    AddLaunchProfiles(temp);
                }
            }
        }
    }

    // Make sure we didn't get a bad profile index
    if (GetActiveProfile() >= GetNumLaunchProfiles())
        SetActiveProfile(GetNumLaunchProfiles() > 0 ? 0 : -1); 
}


Function: CreateNode
Declaration: bool CreateNode(DataNode *node, bool completeSave, bool forceAdd);
Definition:
// ****************************************************************************
// Method: MachineProfile::CreateNode
//
// Purpose: 
//   This method creates a DataNode representation of the object so it can
//   be saved to a config file.
//
//   This differs from the auto-generated one in the following ways:
//    - it checks to see if something is selected when saving instead
//      of checking to see if it differs from the default-constructor version,
//      which lets us select user-set values which differ from system-global
//      ones and save only those fields
//    - it always adds hostNickname, as that's how we identify which
//      host profile is which
//    - we use "completeSave" as the cue as to whether our sub-attribute
//      groups add themselves, overriding forceAdd when descending to them
//    - since host nickname is always saved, we always add to the parent node
//
// Programmer: Jeremy Meredith
// Creation:   April 29, 2010
//
// Modifications:
//   
// ****************************************************************************

bool
MachineProfile::CreateNode(DataNode *parentNode,
                           bool completeSave, bool forceAdd)
{
    if(parentNode == 0)
        return false;

    // Create a node for MachineProfile.
    DataNode *node = new DataNode("MachineProfile");

    node->AddNode(new DataNode("hostNickname", hostNickname));

    if(completeSave || IsSelected(ID_host))
        node->AddNode(new DataNode("host", host));

    if(completeSave || IsSelected(ID_userName))
        node->AddNode(new DataNode("userName", userName));

    if(completeSave || IsSelected(ID_hostAliases))
        node->AddNode(new DataNode("hostAliases", hostAliases));

    if(completeSave || IsSelected(ID_directory))
        node->AddNode(new DataNode("directory", directory));

    if(completeSave || IsSelected(ID_shareOneBatchJob))
        node->AddNode(new DataNode("shareOneBatchJob", shareOneBatchJob));

    if(completeSave || IsSelected(ID_sshPortSpecified))
        node->AddNode(new DataNode("sshPortSpecified", sshPortSpecified));

    if(completeSave || IsSelected(ID_sshPort))
        node->AddNode(new DataNode("sshPort", sshPort));

    if(completeSave || IsSelected(ID_clientHostDetermination))
        node->AddNode(new DataNode("clientHostDetermination", ClientHostDetermination_ToString(clientHostDetermination)));

    if(completeSave || IsSelected(ID_manualClientHostName))
        node->AddNode(new DataNode("manualClientHostName", manualClientHostName));

    if(completeSave || IsSelected(ID_tunnelSSH))
        node->AddNode(new DataNode("tunnelSSH", tunnelSSH));

    for(size_t i = 0; i < launchProfiles.size(); ++i)
        launchProfiles[i]->CreateNode(node, completeSave,
                     completeSave); // (only force an add for a complete save)

    if(completeSave || IsSelected(ID_activeProfile))
        node->AddNode(new DataNode("activeProfile", activeProfile));

    // Add the node to the parent node.
    parentNode->AddNode(node);
    return true;
}

Function: SelectOnlyDifferingFields
Declaration: void SelectOnlyDifferingFields(MachineProfile &other);
Definition:
// ****************************************************************************
// Method:  MachineProfile::SelectOnlyDifferingFields
//
// Purpose:
//   Select only fields which differ from a compared attribute.
//
// Arguments:
//   other      the profile to compare against
//
// Programmer:  Jeremy Meredith
// Creation:    April 29, 2010
//
// ****************************************************************************

void
MachineProfile::SelectOnlyDifferingFields(MachineProfile &other)
{
    UnSelectAll();

    if (host != other.host)
        Select(ID_host,                    (void *)&host);
    if (userName != other.userName)
        Select(ID_userName,                (void *)&userName);
    if (hostAliases != other.hostAliases)
        Select(ID_hostAliases,             (void *)&hostAliases);
    if (hostNickname != other.hostNickname)
        Select(ID_hostNickname,            (void *)&hostNickname);
    if (directory != other.directory)
        Select(ID_directory,               (void *)&directory);
    if (shareOneBatchJob != other.shareOneBatchJob)
        Select(ID_shareOneBatchJob,        (void *)&shareOneBatchJob);
    if (sshPortSpecified != other.sshPortSpecified)
        Select(ID_sshPortSpecified,        (void *)&sshPortSpecified);
    if (sshPort != other.sshPort)
        Select(ID_sshPort,                 (void *)&sshPort);
    if (clientHostDetermination != other.clientHostDetermination)
        Select(ID_clientHostDetermination, (void *)&clientHostDetermination);
    if (manualClientHostName != other.manualClientHostName)
        Select(ID_manualClientHostName,    (void *)&manualClientHostName);
    if (tunnelSSH != other.tunnelSSH)
        Select(ID_tunnelSSH,               (void *)&tunnelSSH);
    if (activeProfile != other.activeProfile)
        Select(ID_activeProfile,           (void *)&activeProfile);

    for (int i=0; i<GetNumLaunchProfiles(); i++)
    {
        LaunchProfile &lp = GetLaunchProfiles(i);
        lp.SelectAll();
        for (int j=0; j<other.GetNumLaunchProfiles(); j++)
        {
            LaunchProfile &otherlp = other.GetLaunchProfiles(j);
            if (lp.GetProfileName() == otherlp.GetProfileName())
            {
                lp.SelectOnlyDifferingFields(otherlp);
                break;
            }
        }
    }
}