From: Ickhee Woo Date: Tue, 29 Aug 2017 06:49:22 +0000 (+0900) Subject: [TCSACR-40][Add] added new API for SyncManager X-Git-Tag: preview1-00151~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a3bf3ca0080a36850bf577d76140694ad47d2386;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [TCSACR-40][Add] added new API for SyncManager Change-Id: I0253bfecdc429a304f1e32e480d2cdcc339b7fdb Signed-off-by: Ickhee Woo --- diff --git a/pkg/PlatformFileList.txt b/pkg/PlatformFileList.txt index a5b8c0712..d98f125ad 100644 --- a/pkg/PlatformFileList.txt +++ b/pkg/PlatformFileList.txt @@ -7,6 +7,7 @@ res/maps_marker_sticker_72.png #mobile #mobile-emul #tv Tizen.Account.AccountManager.dll #mobile #mobile-emul #ivi #wearable Tizen.Account.FidoClient.dll #mobile #mobile-emul #wearable Tizen.Account.OAuth2.dll #mobile #mobile-emul #ivi #wearable +Tizen.Account.SyncManager.dll #mobile #mobile-emul #wearable Tizen.Applications.Alarm.dll #common #mobile #mobile-emul #tv #ivi #wearable Tizen.Applications.AttachPanel.dll #mobile #mobile-emul Tizen.Applications.Badge.dll #mobile #mobile-emul #ivi diff --git a/pkg/Tizen.NET.Private.sln b/pkg/Tizen.NET.Private.sln index c4448d097..8a6f048a0 100644 --- a/pkg/Tizen.NET.Private.sln +++ b/pkg/Tizen.NET.Private.sln @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Account.FidoClient", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Account.OAuth2", "..\src\Tizen.Account.OAuth2\Tizen.Account.OAuth2.csproj", "{CDBB2633-FE0B-485E-B864-DCA9240E6F7D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Account.SyncManager", "..\src\Tizen.Account.SyncManager\Tizen.Account.SyncManager.csproj", "{219B1BF6-E17C-42BC-82A3-7B0C81E23AA6}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Applications.Alarm", "..\src\Tizen.Applications.Alarm\Tizen.Applications.Alarm.csproj", "{6B8722E8-94A4-4739-B0E3-14F1B158BC81}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Applications.AttachPanel", "..\src\Tizen.Applications.AttachPanel\Tizen.Applications.AttachPanel.csproj", "{3BACD1BC-613C-4A68-87F2-789B5937FBF6}" @@ -240,6 +242,18 @@ Global {CDBB2633-FE0B-485E-B864-DCA9240E6F7D}.Release|x64.Build.0 = Release|x64 {CDBB2633-FE0B-485E-B864-DCA9240E6F7D}.Release|x86.ActiveCfg = Release|x86 {CDBB2633-FE0B-485E-B864-DCA9240E6F7D}.Release|x86.Build.0 = Release|x86 + {219B1BF6-E17C-42BC-82A3-7B0C81E23AA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {219B1BF6-E17C-42BC-82A3-7B0C81E23AA6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {219B1BF6-E17C-42BC-82A3-7B0C81E23AA6}.Debug|x64.ActiveCfg = Debug|x64 + {219B1BF6-E17C-42BC-82A3-7B0C81E23AA6}.Debug|x64.Build.0 = Debug|x64 + {219B1BF6-E17C-42BC-82A3-7B0C81E23AA6}.Debug|x86.ActiveCfg = Debug|x86 + {219B1BF6-E17C-42BC-82A3-7B0C81E23AA6}.Debug|x86.Build.0 = Debug|x86 + {219B1BF6-E17C-42BC-82A3-7B0C81E23AA6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {219B1BF6-E17C-42BC-82A3-7B0C81E23AA6}.Release|Any CPU.Build.0 = Release|Any CPU + {219B1BF6-E17C-42BC-82A3-7B0C81E23AA6}.Release|x64.ActiveCfg = Release|x64 + {219B1BF6-E17C-42BC-82A3-7B0C81E23AA6}.Release|x64.Build.0 = Release|x64 + {219B1BF6-E17C-42BC-82A3-7B0C81E23AA6}.Release|x86.ActiveCfg = Release|x86 + {219B1BF6-E17C-42BC-82A3-7B0C81E23AA6}.Release|x86.Build.0 = Release|x86 {6B8722E8-94A4-4739-B0E3-14F1B158BC81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6B8722E8-94A4-4739-B0E3-14F1B158BC81}.Debug|Any CPU.Build.0 = Debug|Any CPU {6B8722E8-94A4-4739-B0E3-14F1B158BC81}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/pkg/Tizen.NET.nuspec b/pkg/Tizen.NET.nuspec index dcd0a807e..a34c60d27 100644 --- a/pkg/Tizen.NET.nuspec +++ b/pkg/Tizen.NET.nuspec @@ -22,6 +22,9 @@ + + + diff --git a/src/Tizen.Account.SyncManager/Interop/Interop.Adapter.cs b/src/Tizen.Account.SyncManager/Interop/Interop.Adapter.cs new file mode 100755 index 000000000..9a05dbc2f --- /dev/null +++ b/src/Tizen.Account.SyncManager/Interop/Interop.Adapter.cs @@ -0,0 +1,28 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Adapter + { + [DllImport(Libraries.SyncManager, EntryPoint = "sync_adapter_set_callbacks")] + internal static extern int SetCallbacks(SyncAdapterStartSyncCallback onStartCb, SyncAdapterCancelSyncCallback onCancelCb); + + [DllImport(Libraries.SyncManager, EntryPoint = "sync_adapter_unset_callbacks")] + internal static extern int UnsetCallbacks(); + + [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] + internal delegate bool SyncAdapterStartSyncCallback(IntPtr account, string syncJobName, string syncCapability, IntPtr syncJobUserData); + + [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] + internal delegate void SyncAdapterCancelSyncCallback(IntPtr account, string syncJobName, string syncCapability, IntPtr syncJobUserData); + } +} diff --git a/src/Tizen.Account.SyncManager/Interop/Interop.Libraries.cs b/src/Tizen.Account.SyncManager/Interop/Interop.Libraries.cs new file mode 100755 index 000000000..837e50b4d --- /dev/null +++ b/src/Tizen.Account.SyncManager/Interop/Interop.Libraries.cs @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +internal static partial class Interop +{ + /// + /// Wrapper class for maintaining names of dependent native libraries. + /// + internal static partial class Libraries + { + public const string SyncManager = "libcore-sync-client.so.1"; + public const string Glib = "libglib-2.0.so.0"; + public const string Libc = "libc.so.6"; + } +} diff --git a/src/Tizen.Account.SyncManager/Interop/Interop.Manager.cs b/src/Tizen.Account.SyncManager/Interop/Interop.Manager.cs new file mode 100755 index 000000000..c26969481 --- /dev/null +++ b/src/Tizen.Account.SyncManager/Interop/Interop.Manager.cs @@ -0,0 +1,36 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using System.Runtime.InteropServices; +using Tizen.Applications; +using Tizen.Account.AccountManager; + +internal static partial class Interop +{ + internal static partial class Manager + { + [DllImport(Libraries.SyncManager, EntryPoint = "sync_manager_on_demand_sync_job")] + internal static extern int RequestOnDemandSyncJob(SafeAccountHandle account, string syncJobName, int syncOption, SafeBundleHandle syncJobUserData, out int syncJobId); + + [DllImport(Libraries.SyncManager, EntryPoint = "sync_manager_add_periodic_sync_job")] + internal static extern int AddPeriodicSyncJob(SafeAccountHandle account, string syncJobName, int syncPeriod, int syncOption, SafeBundleHandle syncJobUserData, out int syncJobId); + + [DllImport(Libraries.SyncManager, EntryPoint = "sync_manager_add_data_change_sync_job")] + internal static extern int AddDataChangeSyncJob(SafeAccountHandle account, string syncCapability, int syncOption, SafeBundleHandle syncJobUserData, out int syncJobId); + + [DllImport(Libraries.SyncManager, EntryPoint = "sync_manager_remove_sync_job")] + internal static extern int RemoveSyncJob(int syncJobId); + + [DllImport(Libraries.SyncManager, EntryPoint = "sync_manager_foreach_sync_job")] + internal static extern int ForeachSyncJob(SyncManagerSyncJobCallback syncJobCb, IntPtr userData); + + [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] + internal delegate bool SyncManagerSyncJobCallback(IntPtr account, string syncJobName, string syncCapability, int syncJobId, IntPtr syncJobUserData, IntPtr userData); + } +} diff --git a/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager.csproj b/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager.csproj new file mode 100644 index 000000000..a552e3fc9 --- /dev/null +++ b/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager.csproj @@ -0,0 +1,16 @@ + + + + + netstandard1.6 + + + + + + + + + + + diff --git a/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager.sln b/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager.sln new file mode 100755 index 000000000..14b65a79a --- /dev/null +++ b/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.13 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Account.SyncManager", "Tizen.Account.SyncManager.csproj", "{16028D3D-9DA0-466A-9CE4-EE8790F450D6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {16028D3D-9DA0-466A-9CE4-EE8790F450D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16028D3D-9DA0-466A-9CE4-EE8790F450D6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16028D3D-9DA0-466A-9CE4-EE8790F450D6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16028D3D-9DA0-466A-9CE4-EE8790F450D6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/Enumerations.cs b/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/Enumerations.cs new file mode 100755 index 000000000..4befba67c --- /dev/null +++ b/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/Enumerations.cs @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Account.SyncManager +{ + /// + /// Enumeration for the Sync option + /// + [Flags] + public enum SyncOption + { + /// + /// Sync job will be operated normally + /// + None = 0, + + /// + /// Sync job will be operated as soon as possible + /// + Expedited = 0X01, + + /// + /// Sync job will not be performed again when it fails + /// + NoRetry = 0X02, + } + + /// + /// Enumeration for the Sync period + /// + public enum SyncPeriod + { + /// + /// Sync within 30 minutes + /// + ThirtyMin = 0, + + /// + /// Sync within 1 hour + /// + OneHour, + + /// + /// Sync within 2 hours + /// + TwoHours, + + /// + /// Sync within 3 hours + /// + ThreeHours, + + /// + /// Sync within 6 hours + /// + SixHours, + + /// + /// Sync within 12 hours + /// + TwelveHours, + + /// + /// Sync within 1 day + /// + OneDay, + } +} + diff --git a/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/ErrorFactory.cs b/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/ErrorFactory.cs new file mode 100755 index 000000000..79f1af9cc --- /dev/null +++ b/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/ErrorFactory.cs @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using Tizen.Internals.Errors; + +namespace Tizen.Account.SyncManager +{ + internal enum SyncManagerErrorCode + { + None = ErrorCode.None, + NotSupported = ErrorCode.NotSupported, + OutOfMemory = ErrorCode.OutOfMemory, + InvalidParameter = ErrorCode.InvalidParameter, + InvalidOperation = ErrorCode.InvalidOperation, + PermissionDenied = ErrorCode.PermissionDenied, + IoError = ErrorCode.IoError, + AlreadyInProgress = ErrorCode.AlreadyInProgress, + QuotaExceeded = ErrorCode.QuotaExceeded, + SystemError = -0x01020000 | 0X01, + AdapterNotFound = -0x01020000 | 0X02 + } + + internal class ErrorFactory + { + internal static string LogTag = "Tizen.Account.SyncManager"; + + internal static Exception GetException(int error) + { + if ((SyncManagerErrorCode)error == SyncManagerErrorCode.NotSupported) + { + return new NotSupportedException("Not supported (%http://tizen.org/feature/account.sync)"); + } + else if ((SyncManagerErrorCode)error == SyncManagerErrorCode.OutOfMemory) + { + return new OutOfMemoryException("Out of memory"); + } + else if ((SyncManagerErrorCode)error == SyncManagerErrorCode.InvalidParameter) + { + return new ArgumentException("Invalid parameter"); + } + else if ((SyncManagerErrorCode)error == SyncManagerErrorCode.InvalidOperation) + { + return new InvalidOperationException("Invalid operation"); + } + else if ((SyncManagerErrorCode)error == SyncManagerErrorCode.PermissionDenied) + { + return new UnauthorizedAccessException("Permission denied (%http://tizen.org/privilege/alarm.set, %http://tizen.org/privilege/calendar.read, %http://tizen.org/privilege/contact.read)"); + } + else if ((SyncManagerErrorCode)error == SyncManagerErrorCode.IoError) + { + return new Exception("IO error occured"); + } + else if ((SyncManagerErrorCode)error == SyncManagerErrorCode.AlreadyInProgress) + { + return new InvalidOperationException("Sync is already in progress"); + } + else if ((SyncManagerErrorCode)error == SyncManagerErrorCode.QuotaExceeded) + { + return new InvalidOperationException("Quota for sync jobs exceeded"); + } + else if ((SyncManagerErrorCode)error == SyncManagerErrorCode.SystemError) + { + return new Exception("System error occured"); + } + else if ((SyncManagerErrorCode)error == SyncManagerErrorCode.AdapterNotFound) + { + return new InvalidOperationException("Sync adapter couldn't be found"); + } + else + { + return new Exception("Unknown error"); + } + } + } +} + diff --git a/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/SyncAdapter.cs b/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/SyncAdapter.cs new file mode 100755 index 000000000..8a59593da --- /dev/null +++ b/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/SyncAdapter.cs @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using Tizen.Applications; +using Tizen.Account.AccountManager; + +namespace Tizen.Account.SyncManager +{ + /// + /// The class contains the delegates to be called upon scheduling a sync operation + /// + public class SyncAdapter + { + Interop.Adapter.SyncAdapterStartSyncCallback _startSyncCallback; + Interop.Adapter.SyncAdapterCancelSyncCallback _cancelSyncCallback; + + /// + /// Callback function for Sync Adapter's start sync request + /// + /// The sync job parameters corresponding to the sync request. + /// true if sync operation is success, @c false otherwise. + public delegate bool StartSyncCallback(SyncJobData syncParameters); + + /// + /// Callback function for Sync Adapter's cancel sync request. + /// + /// The sync job parameters corresponding to the sync request. + public delegate void CancelSyncCallback(SyncJobData syncParameters); + + /// + /// Sets client (Sync Adapter) callback functions + /// + /// A callback function to be called by Sync Manager for performing sync operation. + /// A callback function to be called by Sync Manager for cancelling sync operation. + /// Thrown when any of the arguments are null. + /// Thrown when the application calling this API cannot be a sync adapter. + public void SetSyncEventCallbacks(StartSyncCallback startSyncCb, CancelSyncCallback cancelSyncCb) + { + if (startSyncCb == null || cancelSyncCb == null) + { + throw new ArgumentNullException(); + } + + _startSyncCallback = (IntPtr accountHandle, string syncJobName, string syncCapability, IntPtr syncJobUserData) => + { + Log.Debug(ErrorFactory.LogTag, "Start sync event received"); + + AccountManager.Account account = new AccountManager.Account(new SafeAccountHandle(accountHandle, true)); + Bundle bundle = new Bundle(new SafeBundleHandle(syncJobUserData, true)); + + SyncJobData syncJobData = new SyncJobData() + { + Account = account, + SyncJobName = syncJobName, + UserData = bundle + }; + + return startSyncCb(syncJobData); + }; + + _cancelSyncCallback = (IntPtr accountHandle, string syncJobName, string syncCapability, IntPtr syncJobUserData) => + { + Log.Debug(ErrorFactory.LogTag, "cancel sync event received"); + + AccountManager.Account account = new AccountManager.Account(new SafeAccountHandle(accountHandle, true)); + Bundle bundle = new Bundle(new SafeBundleHandle(syncJobUserData, true)); + + SyncJobData syncJobData = new SyncJobData() + { + Account = account, + SyncJobName = syncJobName, + UserData = bundle + }; + + cancelSyncCb(syncJobData); + }; + + int ret = Interop.Adapter.SetCallbacks(_startSyncCallback, _cancelSyncCallback); + if (ret != (int)SyncManagerErrorCode.None) + { + Log.Error(ErrorFactory.LogTag, "Failed to set callbacks"); + throw ErrorFactory.GetException(ret); + } + } + + /// + /// Unsets client (Sync Adapter) callback functions + /// + /// Thrown when sync manager internal error occurs. + public void UnsetSyncEventCallbacks() + { + int ret = Interop.Adapter.UnsetCallbacks(); + if (ret != (int)SyncManagerErrorCode.None) + { + Log.Error(ErrorFactory.LogTag, "Failed to unset callbacks"); + throw ErrorFactory.GetException(ret); + } + } + } +} + diff --git a/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/SyncClient.cs b/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/SyncClient.cs new file mode 100755 index 000000000..4c82b8543 --- /dev/null +++ b/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/SyncClient.cs @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections.Generic; +using Tizen.Applications; +using Tizen.Account.AccountManager; + +namespace Tizen.Account.SyncManager +{ + /// + /// The SyncClient APIs for managing the sync operations. Applications will call these APIs to schedule their sync operations. + /// Sync service maintains sync requests from all the applications and invokes their respective callback methods to perform account synchronization operations. + /// + public static class SyncClient + { + /// + /// The constructor + /// + static SyncClient() + { + } + + /// + /// Requests Sync Manager to perform one time sync operation + /// + /// Sync job information of the sync job request. + /// sync options determine an way to operate sync job and can be used as ORing. + /// Thrown when any of the arugments are null. + /// Thrown when the application calling this api doesn't have a sync adapter. + /// A unique value which can manage sync jobs. The number of sync job id is limited as less than a hundred. + public static int RequestOnDemandSyncJob(SyncJobData request, SyncOption syncOptions) + { + if (request == null || request.SyncJobName == null) + { + throw new ArgumentNullException(); + } + + SafeAccountHandle accountHandle = (request.Account != null) ? request.Account.SafeAccountHandle : new SafeAccountHandle(); + SafeBundleHandle bundleHandle = (request.UserData != null) ? request.UserData.SafeBundleHandle : new SafeBundleHandle(); + + int id = 0; + int ret = Interop.Manager.RequestOnDemandSyncJob(accountHandle, request.SyncJobName, (int)syncOptions, bundleHandle, out id); + if (ret != (int)SyncManagerErrorCode.None) + { + Log.Error(ErrorFactory.LogTag, "Failed to request on demand sync job"); + throw ErrorFactory.GetException(ret); + } + return id; + } + + /// + /// Requests Sync Manager to perform periodic sync operations + /// + /// Sync job information of the sync job request. + /// Determines time interval of periodic sync. The periodic sync operation can be triggered in that interval, but it does not guarantee exact time. The minimum value is 30 minutes. + /// sync options determine an way to operate sync job and can be used as ORing. + /// http://tizen.org/privilege/alarm.set + /// In case of privilege not defined. + /// Thrown when any of the arguments are null. + /// Thrown when the application calling this API doesn't have a sync adapter. + /// A unique value which can manage sync jobs. The number of sync job id is limited as less than a hundred. + public static int AddPeriodicSyncJob(SyncJobData request, SyncPeriod period, SyncOption syncOptions) + { + if (request == null || request.SyncJobName == null) + { + throw new ArgumentNullException(); + } + + SafeAccountHandle accountHandle = (request.Account != null) ? request.Account.SafeAccountHandle : new SafeAccountHandle(); + SafeBundleHandle bundleHandle = (request.UserData != null) ? request.UserData.SafeBundleHandle : new SafeBundleHandle(); + + int id = 0; + int ret = Interop.Manager.AddPeriodicSyncJob(accountHandle, request.SyncJobName, (int) period, (int)syncOptions, bundleHandle, out id); + if (ret != (int)SyncManagerErrorCode.None) + { + Log.Error(ErrorFactory.LogTag, "Failed to add periodic sync job"); + throw ErrorFactory.GetException(ret); + } + return id; + } + + /// + /// Requests Sync Manager to perform sync operations whenever corresponding DB changed + /// + /// Sync job information of the sync job request. + /// sync options determine an way to operate sync job and can be used as ORing. + /// http://tizen.org/privilege/calendar.read + /// http://tizen.org/privilege/contact.read + /// In case of privilege not defined. + /// Thrown when any of the arguments are null. + /// Thrown when the application calling this API doesn't have a sync adapter. + /// A unique value which can manage sync jobs. The number of sync job id is limited as less than a hundred. + public static int AddDataChangeSyncJob(SyncJobData request, SyncOption syncOptions) + { + if (request == null || request.SyncJobName == null) + { + throw new ArgumentNullException(); + } + + SafeAccountHandle accountHandle = (request.Account != null) ? request.Account.SafeAccountHandle : new SafeAccountHandle(); + SafeBundleHandle bundleHandle = (request.UserData != null) ? request.UserData.SafeBundleHandle : new SafeBundleHandle(); + + int id = 0; + int ret = Interop.Manager.AddDataChangeSyncJob(accountHandle, request.SyncJobName, (int)syncOptions, bundleHandle, out id); + if (ret != (int)SyncManagerErrorCode.None) + { + Log.Error(ErrorFactory.LogTag, "Failed to add data change sync job"); + throw ErrorFactory.GetException(ret); + } + return id; + } + + /// + /// Get all the sync jobs registered with the sync manager + /// + /// + /// Returns the list of SyncJobData corresponding to sync requests. + /// + public static IEnumerable> GetAllSyncJobs() + { + IDictionary syncJobs = new Dictionary(); + Interop.Manager.SyncManagerSyncJobCallback cb = (IntPtr accountHandle, string syncJobName, string syncCapability, int syncJobId, IntPtr syncJobUserData, IntPtr userData) => + { + AccountManager.Account account = new AccountManager.Account(new SafeAccountHandle(accountHandle, true)); + Bundle bundle = new Bundle(new SafeBundleHandle(syncJobUserData, true)); + + SyncJobData syncJobData = new SyncJobData(); + syncJobData.Account = account; + if (syncJobName != null) + syncJobData.SyncJobName = syncJobName; + else + syncJobData.SyncJobName = syncCapability; + syncJobData.UserData = bundle; + + syncJobs.Add(syncJobId, syncJobData); + return true; + }; + + int ret = Interop.Manager.ForeachSyncJob(cb, IntPtr.Zero); + if (ret != (int)SyncManagerErrorCode.None) + { + Log.Error(ErrorFactory.LogTag, "Failed to get registered sync job"); + throw ErrorFactory.GetException(ret); + } + return syncJobs; + } + + /// + /// Requests Sync Manager to remove corresponding sync job job based on id + /// + /// A unique value of each sync job, it can be used to search specific sync job and remove it. + /// Thrown if the input arugments is invalid. + public static void RemoveSyncJob(int id) + { + int ret = Interop.Manager.RemoveSyncJob(id); + if (ret != (int)SyncManagerErrorCode.None) + { + Log.Error(ErrorFactory.LogTag, "Failed to remove sync job"); + throw ErrorFactory.GetException(ret); + } + } + } +} + diff --git a/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/SyncJobData.cs b/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/SyncJobData.cs new file mode 100755 index 000000000..51c20391f --- /dev/null +++ b/src/Tizen.Account.SyncManager/Tizen.Account.SyncManager/SyncJobData.cs @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Tizen.Applications; +using Tizen.Account.AccountManager; + +namespace Tizen.Account.SyncManager +{ + /// + /// Class represents information about a sync job request + /// + public class SyncJobData + { + /// + /// Represents calendar capability + /// + /// + /// If you want to receive notification about calendar database change, assign it to SyncJobName property of SyncJobData object. + /// + public const string CalendarCapability = "http://tizen.org/sync/capability/calendar"; + + /// + /// Represents contact capability + /// + /// + /// If you want to receive notification about contact database change, assign it to SyncJobName property of SyncJobData object. + /// + public const string ContactCapability = "http://tizen.org/sync/capability/contact"; + + /// + /// Represents image capability + /// + /// + /// If you want to receive notification about image database change, assign it to SyncJobName property of SyncJobData object. + /// + public const string ImageCapability = "http://tizen.org/sync/capability/image"; + + /// + /// Represents video capability + /// + /// + /// If you want to receive notification about video database change, assign it to SyncJobName property of SyncJobData object. + /// + public const string VideoCapability = "http://tizen.org/sync/capability/video"; + + /// + /// Represents sound capability + /// + /// + /// If you want to receive notification about sound database change, assign it to SyncJobName property of SyncJobData object. + /// + public const string SoundCapability = "http://tizen.org/sync/capability/sound"; + + /// + /// Represents music capability + /// + /// + /// If you want to receive notification about music database change, assign it to SyncJobName property of SyncJobData object. + /// + public const string MusicCapability = "http://tizen.org/sync/capability/music"; + + /// + /// The account instance on which sync operation was requested or @c null in the case of accountless sync operation + /// + public AccountManager.Account Account { get; set; } + + /// + /// User data which contains additional information related registered sync job + /// + public Bundle UserData { get; set; } + + /// + /// A string representing a sync job which has been operated or capability setting to operate data change sync job + /// + public string SyncJobName { get; set; } + } +} +