Commit 8d90d9ed authored by Romain Bertozzi's avatar Romain Bertozzi

account service: modify bridging

This patch reorganizes the structure of the bridging between the Swift
client and the Daemon.

It isolates the code related to the account service. That's why there
is a renaming of the ConfigurationManagerAdaptor.
We want it to be specialized in what the account service can do.

The files meant to make the bridge between the client and the daemon
are now stored in a dedicated file in the project structure.

The broadcast by NSNotification posts is still used here.

Tuleap: #1405
Change-Id: I2d8f0d361ed9394c98a30b0703ad3d49b18cde4a
parent ce321fbd
This diff is collapsed.
......@@ -91,7 +91,7 @@ struct AccountModel {
get {return (details[accountEnabledKey]?.toBool())!}
set {
details[accountEnabledKey] = newValue.toString()
(ConfigurationManagerAdaptator.sharedManager() as AnyObject).setAccountActive(self.id, active: newValue)
(AccountAdapter.sharedManager() as AnyObject).setAccountActive(self.id, active: newValue)
}
}
......@@ -118,10 +118,10 @@ struct AccountModel {
// MARK: - Init
init(accountID: String) {
id = accountID
details = (ConfigurationManagerAdaptator.sharedManager() as AnyObject).getAccountDetails(id) as! Dictionary<String, String>
details = (AccountAdapter.sharedManager() as AnyObject).getAccountDetails(id) as! Dictionary<String, String>
}
func save() {
(ConfigurationManagerAdaptator.sharedManager() as AnyObject).setAccountDetails(id, details: details)
(AccountAdapter.sharedManager() as AnyObject).setAccountDetails(id, details: details)
}
}
......@@ -2,6 +2,7 @@
* Copyright (C) 2016 Savoir-faire Linux Inc.
*
* Author: Edric Ladent-Milaret <edric.ladent-milaret@savoirfairelinux.com>
* Author: Romain Bertozzi <romain.bertozzi@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -15,28 +16,33 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import <Foundation/Foundation.h>
@interface ConfigurationManagerAdaptator : NSObject
@interface AccountAdapter : NSObject
+ (id)sharedManager;
- (void)registerConfigurationHandler;
- (NSArray*)getAccountList;
- (NSMutableDictionary*)getAccountTemplate:(NSString*)accountType;
- (NSString*)addAccount:(NSDictionary*)details;
- (void)removeAccount:(NSString*)accountID;
- (void)setAccountActive:(NSString*)accountID active:(bool)active;
- (uint64_t)sendAccountTextMessage:(NSString*)accountID
to:(NSString*)to
payloads:(NSDictionary*)payloads;
- (NSDictionary*)getAccountDetails:(NSString*)accountID;
- (NSDictionary*)getVolatileAccountDetails:(NSString*)accountID;
- (void)setAccountDetails:(NSString*)accountID details:(NSDictionary*)details;
- (int)getMessageStatus:(uint64_t)msgID;
- (NSDictionary *)getAccountDetails:(NSString *)accountID;
- (NSDictionary *)getVolatileAccountDetails:(NSString *)accountID;
- (void)setAccountDetails:(NSString *)accountID
details:(NSDictionary *)details;
- (void)setAccountActive:(NSString *)accountID
active:(bool)active;
- (NSMutableDictionary *)getAccountTemplate:(NSString *)accountType;
- (NSString *)addAccount:(NSDictionary *)details;
- (void)removeAccount:(NSString *)accountID;
- (NSArray *)getAccountList;
@end
/*
* Copyright (C) 2016 Savoir-faire Linux Inc.
*
* Author: Edric Ladent-Milaret <edric.ladent-milaret@savoirfairelinux.com>
* Author: Romain Bertozzi <romain.bertozzi@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import "AccountAdapter.h"
#import "Utils.h"
#import "NotificationNames.h"
#import "dring/configurationmanager_interface.h"
@implementation AccountAdapter
using namespace DRing;
#pragma mark Singleton Methods
+ (id)sharedManager {
static AccountAdapter* sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
- (id)init {
if (self = [super init]) {
[self registerConfigurationHandler];
}
return self;
}
#pragma mark -
#pragma mark Callbacks
- (void)registerConfigurationHandler {
std::map<std::string, std::shared_ptr<CallbackWrapperBase>> confHandlers;
confHandlers.insert(exportable_callback<ConfigurationSignal::AccountsChanged>([&]() {
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:kNotificationAccountsChanged
object:[AccountAdapter sharedManager]];
}));
registerConfHandlers(confHandlers);
}
#pragma mark -
#pragma mark Accessors
- (NSDictionary *)getAccountDetails:(NSString *)accountID {
auto accDetails = getAccountDetails(std::string([accountID UTF8String]));
return [Utils mapToDictionnary:accDetails];
}
- (NSDictionary *)getVolatileAccountDetails:(NSString *)accountID {
auto volatileDetails = getVolatileAccountDetails(std::string([accountID UTF8String]));
return [Utils mapToDictionnary:volatileDetails];
}
- (void)setAccountDetails:(NSString *)accountID
details:(NSDictionary *)details {
setAccountDetails(std::string([accountID UTF8String]),[Utils dictionnaryToMap:details]);
}
- (void)setAccountActive:(NSString *)accountID
active:(bool)active {
setAccountActive(std::string([accountID UTF8String]), active);
}
- (NSArray *)getAccountList {
auto accountVector = getAccountList();
return [Utils vectorToArray:accountVector];
}
- (NSString *)addAccount:(NSDictionary *)details {
auto accountID = addAccount([Utils dictionnaryToMap:details]);
return [NSString stringWithUTF8String:accountID.c_str()];
}
- (void)removeAccount:(NSString *)accountID {
removeAccount(std::string([accountID UTF8String]));
}
- (NSMutableDictionary *)getAccountTemplate:(NSString *)accountType {
auto accountTemplate = getAccountTemplate(std::string([accountType UTF8String]));
return [Utils mapToDictionnary:accountTemplate];
}
#pragma mark -
@end
/*
* Copyright (C) 2016 Savoir-faire Linux Inc.
*
* Author: Romain Bertozzi <romain.bertozzi@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef NotificationNames_hpp
#define NotificationNames_hpp
#import <Foundation/Foundation.h>
extern NSString * const kNotificationAccountsChanged;
#endif /* NotificationNames_hpp */
......@@ -18,8 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import UIKit
#include "NotificationNames.h"
extension Notification.Name {
static let accountsChanged = Notification.Name("AccountsChanged")
}
NSString * const kNotificationAccountsChanged = @"AccountsChanged";
......@@ -2,6 +2,7 @@
* Copyright (C) 2016 Savoir-faire Linux Inc.
*
* Author: Edric Ladent-Milaret <edric.ladent-milaret@savoirfairelinux.com>
* Author: Romain Bertozzi <romain.bertozzi@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -15,14 +16,12 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
//
// Use this file to import your target's public headers that you would like to
// expose to Swift.
//
#import "ConfigurationManagerAdaptator.h"
/**
Expose Objective-C bridging classes to Swift.
*/
#import "AccountAdapter.h"
#import "DRingAdapter.h"
#import "NotificationNames.h"
/*
* Copyright (C) 2016 Savoir-faire Linux Inc.
*
* Author: Edric Ladent-Milaret <edric.ladent-milaret@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA.
*/
#import "ConfigurationManagerAdaptator.h"
#import "Utils.h"
#import "dring/configurationmanager_interface.h"
@implementation ConfigurationManagerAdaptator
using namespace DRing;
#pragma mark Singleton Methods
+ (id)sharedManager {
static ConfigurationManagerAdaptator* sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
- (id)init {
if (self = [super init]) {
[self registerConfigurationHandler];
}
return self;
}
- (NSArray*)getAccountList {
auto accountVector = getAccountList();
return [Utils vectorToArray:accountVector];
}
- (NSMutableDictionary*)getAccountTemplate:(NSString*)accountType {
auto accountTemplate =
getAccountTemplate(std::string([accountType UTF8String]));
return [Utils mapToDictionnary:accountTemplate];
}
- (NSString*)addAccount:(NSDictionary*)details {
auto accountID = addAccount([Utils dictionnaryToMap:details]);
return [NSString stringWithUTF8String:accountID.c_str()];
}
- (void)removeAccount:(NSString*)accountID {
removeAccount(std::string([accountID UTF8String]));
}
- (void)setAccountActive:(NSString*)accountID active:(bool)active {
setAccountActive(std::string([accountID UTF8String]), active);
}
- (uint64_t)sendAccountTextMessage:(NSString*)accountID
to:(NSString*)to
payloads:(NSDictionary*)payloads {
return sendAccountTextMessage(std::string([accountID UTF8String]),
std::string([to UTF8String]),
[Utils dictionnaryToMap:payloads]);
}
- (NSDictionary*)getAccountDetails:(NSString*)accountID {
auto accDetails = getAccountDetails(std::string([accountID UTF8String]));
return [Utils mapToDictionnary:accDetails];
}
- (NSDictionary*)getVolatileAccountDetails:(NSString*)accountID {
auto volatileDetails =
getVolatileAccountDetails(std::string([accountID UTF8String]));
return [Utils mapToDictionnary:volatileDetails];
}
- (void)setAccountDetails:(NSString*)accountID details:(NSDictionary*)details {
setAccountDetails(std::string([accountID UTF8String]),
[Utils dictionnaryToMap:details]);
}
- (int)getMessageStatus:(uint64_t)msgID {
return getMessageStatus(msgID);
}
- (void)registerConfigurationHandler {
std::map<std::string, std::shared_ptr<CallbackWrapperBase>> confHandlers;
confHandlers.insert(
exportable_callback<ConfigurationSignal::IncomingAccountMessage>(
[&](const std::string& account_id, const std::string& from,
const std::map<std::string, std::string>& payloads) {
NSDictionary* userInfo = @{
@"accountID" : [NSString stringWithUTF8String:account_id.c_str()],
@"from" : [NSString stringWithUTF8String:from.c_str()],
@"payloads" : [Utils mapToDictionnary:payloads]
};
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:@"IncomingAccountMessage"
object:self
userInfo:userInfo];
}));
confHandlers.insert(
exportable_callback<ConfigurationSignal::AccountsChanged>([&]() {
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:@"AccountsChanged"
object:[ConfigurationManagerAdaptator sharedManager]];
}));
registerConfHandlers(confHandlers);
}
@end
......@@ -21,7 +21,7 @@
class AccountsService {
// MARK: - Properties
fileprivate let confAdapter = ConfigurationManagerAdaptator.sharedManager() as AnyObject
fileprivate let confAdapter = AccountAdapter.sharedManager() as AnyObject
/// Fileprivate Accounts list.
///
......@@ -49,7 +49,7 @@ class AccountsService {
fileprivate init() {
accountList = []
NotificationCenter.default.addObserver(forName: .accountsChanged,
NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: kNotificationAccountsChanged),
object: nil,
queue: nil,
using: { _ in
......
......@@ -24,7 +24,7 @@
// expose to Swift.
//
#import "ConfigurationManagerAdaptator.h"
#import "AccountAdapter.h"
#import "DRingAdapter.h"
#import "FixtureFailInitDRingAdapter.h"
#import "FixtureFailStartDRingAdapter.h"
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