OSDN Git Service

1febef6fc5d7d791adce8346ba357b62a2d03e37
[tjqt4port/tj2qt4.git] / taskjuggler / Allocation.cpp
1 /*
2  * Allocation.cpp - TaskJuggler
3  *
4  * Copyright (c) 2001, 2002 by Chris Schlaeger <cs@suse.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of version 2 of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * $Id$
11  */
12
13 #include "ResourceList.h"
14 #include "Allocation.h"
15 #include "ReportXML.h"
16
17 #define KW(a) a
18
19 /* -- DTD --
20     <!ELEMENT Allocation (Load, Persistent)>
21     <!ELEMENT Load       (#PCDATA)>
22     <!ELEMENT Persistent (#PCDATA)>
23     <!ATTLIST Allocation ResourceID CDATA #REQUIRED>
24   /-- DTD --/
25 */
26
27 /* Constructor */
28 Allocation::Allocation( Resource *r) :
29         load(100), persistent(FALSE), lockedResource(0)
30 {
31         candidates.append(r);
32         selectionMode = order;
33 }
34
35 /* Creation of the XML Reprsentation of the Allocation */
36 QDomElement Allocation::xmlElement( QDomDocument& doc )
37 {
38    QDomElement elem = doc.createElement( "Allocation" );
39    elem.appendChild(ReportXML::createXMLElem( doc, "Load", QString::number(getLoad()) ));
40    elem.appendChild(ReportXML::createXMLElem( doc, "Persistent", isPersistent() ? "Yes":"No" ));
41    elem.setAttribute( "ResourceID", candidates.first()->getId());
42    
43    /* candidates are missing TODO */
44    return elem;
45
46 }
47
48 bool
49 Allocation::setSelectionMode(const QString& smt)
50 {
51         if (smt == KW("order"))
52                 selectionMode = order;
53         else if (smt == KW("minloaded"))
54                 selectionMode = minLoaded;
55         else if (smt == KW("maxloaded"))
56                 selectionMode = maxLoaded;
57         else if (smt == KW("random"))
58                 selectionMode = random;
59         else
60                 return FALSE;
61         return TRUE;
62 }
63