Skip to content

Commit

Permalink
[ssu] Use enum Ssu::DeviceMode instead of int
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Perl authored and thp committed Feb 2, 2015
1 parent 0b1a248 commit ffa3b90
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 68 deletions.
4 changes: 2 additions & 2 deletions libssu/ssu.cpp
Expand Up @@ -125,7 +125,7 @@ QString Ssu::flavour(){
return settings->flavour();
}

int Ssu::deviceMode(){
Ssu::DeviceModeFlags Ssu::deviceMode(){
SsuCoreConfig *settings = SsuCoreConfig::instance();
return settings->deviceMode();
}
Expand All @@ -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);
}
Expand Down
108 changes: 57 additions & 51 deletions libssu/ssu.h
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -203,4 +207,6 @@ class Ssu: public QObject {
void credentialsChanged();
};

Q_DECLARE_OPERATORS_FOR_FLAGS(Ssu::DeviceModeFlags)

#endif
6 changes: 3 additions & 3 deletions libssu/ssucoreconfig.cpp
Expand Up @@ -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){
Expand Down Expand Up @@ -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){
Expand Down
4 changes: 2 additions & 2 deletions libssu/ssucoreconfig.h
Expand Up @@ -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
Expand All @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion ssucli/ssucli.cpp
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions ssud/ssud.cpp
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions ssud/ssud.h
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions tests/ut_coreconfig/coreconfigtest.cpp
Expand Up @@ -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(){
Expand Down

0 comments on commit ffa3b90

Please sign in to comment.