aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc
diff options
context:
space:
mode:
Diffstat (limited to 'src/objc')
-rw-r--r--src/objc/nntp/MCONNTP.h1
-rw-r--r--src/objc/nntp/MCONNTPFetchServerTimeOperation.h35
-rw-r--r--src/objc/nntp/MCONNTPFetchServerTimeOperation.mm70
-rw-r--r--src/objc/nntp/MCONNTPSession.h10
-rw-r--r--src/objc/nntp/MCONNTPSession.mm5
5 files changed, 121 insertions, 0 deletions
diff --git a/src/objc/nntp/MCONNTP.h b/src/objc/nntp/MCONNTP.h
index 7e2f1072..364db25b 100644
--- a/src/objc/nntp/MCONNTP.h
+++ b/src/objc/nntp/MCONNTP.h
@@ -17,6 +17,7 @@
#include <MailCore/MCONNTPFetchArticlesOperation.h>
#include <MailCore/MCONNTPListNewsgroupsOperation.h>
#include <MailCore/MCONNTPFetchOverviewOperation.h>
+#include <MailCore/MCONNTPFetchServerTimeOperation.h>
#include <MailCore/MCONNTPGroupInfo.h>
#endif
diff --git a/src/objc/nntp/MCONNTPFetchServerTimeOperation.h b/src/objc/nntp/MCONNTPFetchServerTimeOperation.h
new file mode 100644
index 00000000..a06dd746
--- /dev/null
+++ b/src/objc/nntp/MCONNTPFetchServerTimeOperation.h
@@ -0,0 +1,35 @@
+//
+// MCONNTPFetchServerTimeOperation.h
+// mailcore2
+//
+// Created by Robert Widmann on 10/21/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCONNTPFETCHSERVERTIMEOPERATION_H
+
+#define MAILCORE_MCONNTPFETCHSERVERTIMEOPERATION_H
+
+#import <Foundation/Foundation.h>
+#import <MailCore/MCONNTPOperation.h>
+
+@class MCOIndexSet;
+
+/** This is an asynchronous operation that will fetch the list of a messages on the NNTP server. */
+@interface MCONNTPFetchServerTimeOperation : MCONNTPOperation
+
+/**
+ Starts the asynchronous fetch operation.
+
+ @param completionBlock Called when the operation is finished.
+
+ - On success `error` will be nil and `date` will be the server's date and time as an NSDate.
+
+ - On failure, `error` will be set with `MCOErrorDomain` as domain and an
+ error code available in MCOConstants.h, `messages` will be null
+ */
+- (void) start:(void (^)(NSError * error, NSDate * date))completionBlock;
+
+@end
+
+#endif
diff --git a/src/objc/nntp/MCONNTPFetchServerTimeOperation.mm b/src/objc/nntp/MCONNTPFetchServerTimeOperation.mm
new file mode 100644
index 00000000..a2f51f91
--- /dev/null
+++ b/src/objc/nntp/MCONNTPFetchServerTimeOperation.mm
@@ -0,0 +1,70 @@
+//
+// MCONNTPFetchServerTimeOperation.m
+// mailcore2
+//
+// Created by Robert Widmann on 10/21/14.
+// Copyright (c) 2014 MailCore. All rights reserved.
+//
+
+#import "MCONNTPFetchServerTimeOperation.h"
+
+#include "MCAsyncNNTP.h"
+
+#import "MCOOperation+Private.h"
+#import "MCOUtils.h"
+
+typedef void (^CompletionType)(NSError *error, NSDate * date);
+
+@implementation MCONNTPFetchServerTimeOperation {
+ CompletionType _completionBlock;
+}
+
+#define nativeType mailcore::NNTPFetchServerTimeOperation
+
++ (void) load
+{
+ MCORegisterClass(self, &typeid(nativeType));
+}
+
++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
+{
+ nativeType * op = (nativeType *) object;
+ return [[[self alloc] initWithMCOperation:op] autorelease];
+}
+
+- (void) dealloc
+{
+ [_completionBlock release];
+ [super dealloc];
+}
+
+- (void) start:(void (^)(NSError *error, NSDate * date))completionBlock
+{
+ _completionBlock = [completionBlock copy];
+ [self start];
+}
+
+- (void) cancel
+{
+ [_completionBlock release];
+ _completionBlock = nil;
+ [super cancel];
+}
+
+- (void) operationCompleted
+{
+ if (_completionBlock == NULL)
+ return;
+
+ nativeType *op = MCO_NATIVE_INSTANCE;
+ if (op->error() == mailcore::ErrorNone) {
+ _completionBlock(nil, [NSDate dateWithTimeIntervalSince1970:op->time()]);
+ } else {
+ _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil);
+ }
+ [_completionBlock release];
+ _completionBlock = nil;
+}
+
+
+@end
diff --git a/src/objc/nntp/MCONNTPSession.h b/src/objc/nntp/MCONNTPSession.h
index c5fb04cc..63e7467b 100644
--- a/src/objc/nntp/MCONNTPSession.h
+++ b/src/objc/nntp/MCONNTPSession.h
@@ -21,6 +21,7 @@
@class MCONNTPFetchArticleOperation;
@class MCONNTPListNewsgroupsOperation;
@class MCONNTPFetchOverviewOperation;
+@class MCONNTPFetchServerTimeOperation;
@class MCONNTPOperation;
@class MCOIndexSet;
@@ -117,6 +118,15 @@
- (MCONNTPFetchArticleOperation *) fetchArticleOperationWithMessageID:(NSString *)messageID inGroup:(NSString *)group;
/**
+ Returns an operation that will fetch the server's date and time.
+
+ MCONNTPFetchArticleOperation * op = [session fetchServerTimeOperation];
+ [op start:^(NSError * error, NSDate * serverTime) {
+ }];
+ */
+- (MCONNTPFetchServerTimeOperation *) fetchServerTimeOperation;
+
+/**
Returns an operation that will list all available newsgroups.
MCONNTPListNewsgroupsOperation * op = [session listAllNewsgroupsOperation];
diff --git a/src/objc/nntp/MCONNTPSession.mm b/src/objc/nntp/MCONNTPSession.mm
index 094c5886..b9d3573c 100644
--- a/src/objc/nntp/MCONNTPSession.mm
+++ b/src/objc/nntp/MCONNTPSession.mm
@@ -150,6 +150,11 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
return MCO_TO_OBJC_OP(coreOp);
}
+- (MCONNTPFetchServerTimeOperation *) fetchServerTimeOperation {
+ mailcore::NNTPFetchServerTimeOperation * coreOp = MCO_NATIVE_INSTANCE->fetchServerTimeOperation();
+ return MCO_TO_OBJC_OP(coreOp);
+}
+
- (MCONNTPListNewsgroupsOperation *) listAllNewsgroupsOperation {
mailcore::NNTPListNewsgroupsOperation * coreOp = MCO_NATIVE_INSTANCE->listAllNewsgroupsOperation();
return MCO_TO_OBJC_OP(coreOp);