Commit ffa3b90b authored by Thomas Perl's avatar Thomas Perl Committed by Thomas Perl

[ssu] Use enum Ssu::DeviceMode instead of int

parent 0b1a2487
......@@ -125,7 +125,7 @@ QString Ssu::flavour(){
return settings->flavour();
}
int Ssu::deviceMode(){
Ssu::DeviceModeFlags Ssu::deviceMode(){
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->deviceMode();
}
......@@ -150,7 +150,7 @@ QString Ssu::release(bool rnd){
return settings->release(rnd);
}
void Ssu::setDeviceMode(int mode, int editMode){
void Ssu::setDeviceMode(Ssu::DeviceModeFlags mode, enum Ssu::EditMode editMode){
SsuCoreConfig *settings = SsuCoreConfig::instance();
settings->setDeviceMode(mode, editMode);
}
......
......@@ -22,6 +22,59 @@ class Ssu: public QObject {
friend class UrlResolverTest;
public:
/**
* Filters to control the output of the repository lookup methods
*/
enum RepoFilter {
NoFilter, ///< All repositories (global + user)
UserFilter, ///< Only user configured repositories
BoardFilter, ///< Only global repositories, with user blacklist ignored
BoardFilterUserBlacklist, ///< Only global repositories, with user blacklist applied
};
/**
* List of possible device modes
*
* ReleaseMode is defined to make a switch to allowing RnD and Release
* repositories on a device at the same time easy, if ever needed. Right
* now any mode where RndMode is not set is treated as ReleaseMode.
*/
enum DeviceMode {
DisableRepoManager = 0x1, ///< Disable automagic repository management
RndMode = 0x2, ///< Enable RnD mode for device
ReleaseMode = 0x4, ///< Enable Release mode
LenientMode = 0x8, ///< Disable strict mode (i.e., keep unmanaged repositories)
UpdateMode = 0x10, ///< Do repo isolation and similar bits important for updating devices
};
Q_DECLARE_FLAGS(DeviceModeFlags, DeviceMode)
/**
* A list of types ssu provides shiny values suitable for displaying
*/
enum DisplayType {
DeviceManufacturer = 0, ///< Manufacturer, like ACME Corp. Board mappings key "deviceManufacturer"
DeviceModel, ///< Marketed device name, like Pogoblaster 3000. Board mappings key "prettyModel"
DeviceDesignation, ///< Type designation, like NCC-1701. Beard mappings key "deviceDesignation"
};
/**
* Edit modes for variables containing bitmasks
*/
enum EditMode {
Replace = 0x1, ///< Replace the old value with the new one
Add = 0x2, ///< Make sure the given value is set in the bitmask
Remove = 0x4, ///< Make sure the given value is not set in the bitmask
};
/**
* Return codes to signal success or error conditions
*/
enum ReturnValue {
Success = 0,
ErrUpdateMode = -10,
};
Ssu();
/**
* Find a username/password pair for the given scope
......@@ -76,7 +129,7 @@ class Ssu: public QObject {
/// See SsuCoreConfig::flavour
Q_INVOKABLE QString flavour();
/// See SsuCoreConfig::deviceMode
Q_INVOKABLE int deviceMode();
Q_INVOKABLE DeviceModeFlags deviceMode();
/// See SsuCoreConfig::domain; returns printable version
Q_INVOKABLE QString domain();
/// See SsuCoreConfig::isRegistered
......@@ -86,7 +139,7 @@ class Ssu: public QObject {
/// See SsuCoreConfig::release
Q_INVOKABLE QString release(bool rnd=false);
/// See SsuCoreConfig::setDeviceMode
Q_INVOKABLE void setDeviceMode(int mode, int editMode=Replace);
Q_INVOKABLE void setDeviceMode(DeviceModeFlags mode, enum EditMode editMode=Replace);
/// See SsuCoreConfig::setFlavour
Q_INVOKABLE void setFlavour(QString flavour);
/// See SsuCoreConfig::setRelease
......@@ -96,55 +149,6 @@ class Ssu: public QObject {
/// See SsuCoreConfig::useSslVerify
Q_INVOKABLE bool useSslVerify();
/**
* Filters to control the output of the repository lookup methods
*/
enum RepoFilter {
NoFilter, ///< All repositories (global + user)
UserFilter, ///< Only user configured repositories
BoardFilter, ///< Only global repositories, with user blacklist ignored
BoardFilterUserBlacklist ///< Only global repositories, with user blacklist applied
};
/**
* List of possible device modes
*
* ReleaseMode is defined to make a switch to allowing RnD and Release
* repositories on a device at the same time easy, if ever needed. Right
* now any mode where RndMode is not set is treated as ReleaseMode.
*/
enum DeviceMode {
DisableRepoManager = 0x1, ///< Disable automagic repository management
RndMode = 0x2, ///< Enable RnD mode for device
ReleaseMode = 0x4, ///< Enable Release mode
LenientMode = 0x8, ///< Disable strict mode (i.e., keep unmanaged repositories)
UpdateMode = 0x10 ///< Do repo isolation and similar bits important for updating devices
};
/**
* A list of types ssu provides shiny values suitable for displaying
*/
enum DisplayType {
DeviceManufacturer = 0, ///< Manufacturer, like ACME Corp. Board mappings key "deviceManufacturer"
DeviceModel, ///< Marketed device name, like Pogoblaster 3000. Board mappings key "prettyModel"
DeviceDesignation, ///< Type designation, like NCC-1701. Beard mappings key "deviceDesignation"
};
/**
* Edit modes for variables containing bitmasks
*/
enum EditMode {
Replace = 0x1, ///< Replace the old value with the new one
Add = 0x2, ///< Make sure the given value is set in the bitmask
Remove = 0x4 ///< Make sure the given value is not set in the bitmask
};
/**
* Return codes to signal success or error conditions
*/
enum ReturnValue {
Success = 0,
ErrUpdateMode = -10,
};
private:
QString errorString;
bool errorFlag;
......@@ -203,4 +207,6 @@ class Ssu: public QObject {
void credentialsChanged();
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Ssu::DeviceModeFlags)
#endif
......@@ -54,11 +54,11 @@ QString SsuCoreConfig::flavour(){
return "release";
}
int SsuCoreConfig::deviceMode(){
Ssu::DeviceModeFlags SsuCoreConfig::deviceMode(){
if (!contains("deviceMode"))
return Ssu::ReleaseMode;
else
return value("deviceMode").toInt();
return Ssu::DeviceModeFlags(value("deviceMode").toInt());
}
QString SsuCoreConfig::domain(bool pretty){
......@@ -90,7 +90,7 @@ QString SsuCoreConfig::release(bool rnd){
return value("release").toString();
}
void SsuCoreConfig::setDeviceMode(int mode, int editMode){
void SsuCoreConfig::setDeviceMode(Ssu::DeviceModeFlags mode, enum Ssu::EditMode editMode){
int oldMode = value("deviceMode").toInt();
if ((editMode & Ssu::Add) == Ssu::Add){
......
......@@ -56,7 +56,7 @@ class SsuCoreConfig: public SsuSettings {
/**
* Get the current mode bits for the device
*/
Q_INVOKABLE int deviceMode();
Q_INVOKABLE Ssu::DeviceModeFlags deviceMode();
/**
* Get the current domain used in registration
* Internally - in the domain is replaced by :, if you need
......@@ -82,7 +82,7 @@ class SsuCoreConfig: public SsuSettings {
/**
* Set mode bits for the device
*/
Q_INVOKABLE void setDeviceMode(int mode, int editMode=Ssu::Replace);
Q_INVOKABLE void setDeviceMode(Ssu::DeviceModeFlags mode, enum Ssu::EditMode editMode=Ssu::Replace);
/**
* Set the flavour used when resolving RND repositories
*/
......
......@@ -148,7 +148,7 @@ void SsuCli::optMode(QStringList opt){
reply.waitForFinished();
if (reply.isError()){
qerr << "DBus call failed, falling back to libssu" << endl;
ssu.setDeviceMode(opt.at(2).toInt());
ssu.setDeviceMode(Ssu::DeviceModeFlags(opt.at(2).toInt()));
SsuRepoManager repoManager;
repoManager.update();
......
......@@ -117,12 +117,12 @@ void Ssud::unregisterDevice(){
};
int Ssud::deviceMode(){
Ssu::DeviceModeFlags Ssud::deviceMode(){
autoclose.start();
return ssu.deviceMode();
}
void Ssud::setDeviceMode(int mode){
void Ssud::setDeviceMode(enum Ssu::DeviceMode mode){
ssu.setDeviceMode(mode);
SsuRepoManager repoManager;
......
......@@ -33,8 +33,8 @@ class Ssud: public QObject {
void registerDevice(const QString &username, const QString &password);
void unregisterDevice();
/* repository management */
int deviceMode();
void setDeviceMode(int mode);
Ssu::DeviceModeFlags deviceMode();
void setDeviceMode(enum Ssu::DeviceMode mode);
QString flavour();
void setFlavour(const QString &release);
QString release(bool rnd);
......
......@@ -33,15 +33,15 @@ void CoreconfigTest::testFlavour(){
void CoreconfigTest::testDeviceMode(){
SsuCoreConfig::instance()->remove("deviceMode");
QCOMPARE(SsuCoreConfig::instance()->deviceMode(), (int)Ssu::ReleaseMode);
QCOMPARE(SsuCoreConfig::instance()->deviceMode(), Ssu::ReleaseMode);
SsuCoreConfig::instance()->setDeviceMode(Ssu::ReleaseMode, Ssu::Add);
QCOMPARE(SsuCoreConfig::instance()->deviceMode(), (int)Ssu::ReleaseMode);
QCOMPARE(SsuCoreConfig::instance()->deviceMode(), Ssu::ReleaseMode);
SsuCoreConfig::instance()->setDeviceMode(Ssu::LenientMode, Ssu::Add);
QCOMPARE(SsuCoreConfig::instance()->deviceMode(), (int)Ssu::ReleaseMode | Ssu::LenientMode);
QCOMPARE(SsuCoreConfig::instance()->deviceMode(), Ssu::ReleaseMode | Ssu::LenientMode);
SsuCoreConfig::instance()->setDeviceMode(Ssu::ReleaseMode, Ssu::Remove);
QCOMPARE(SsuCoreConfig::instance()->deviceMode(), (int)Ssu::LenientMode);
QCOMPARE(SsuCoreConfig::instance()->deviceMode(), Ssu::LenientMode);
SsuCoreConfig::instance()->setDeviceMode(Ssu::ReleaseMode, Ssu::Replace);
QCOMPARE(SsuCoreConfig::instance()->deviceMode(), (int)Ssu::ReleaseMode);
QCOMPARE(SsuCoreConfig::instance()->deviceMode(), Ssu::ReleaseMode);
}
void CoreconfigTest::testDomain(){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment