Skip to content

Commit

Permalink
[Tizen.Core] Add new API for providing a new main loop model (Samsung…
Browse files Browse the repository at this point in the history
…#6296)

* [Tizen.Core] Add new Tizen.Core library

Signed-off-by: Hwankyu Jhun <[email protected]>

* Remove example code from TCoreTask.Running property

Signed-off-by: Hwankyu Jhun <[email protected]>

* Update descriptions

Signed-off-by: Hwankyu Jhun <[email protected]>

* Save unsaved code

Signed-off-by: Hwankyu Jhun <[email protected]>

* Update markdown file

Signed-off-by: Hwankyu Jhun <[email protected]>

* Update descriptions

Signed-off-by: Hwankyu Jhun <[email protected]>

---------

Signed-off-by: Hwankyu Jhun <[email protected]>
  • Loading branch information
hjhun authored and bshsqa committed Sep 25, 2024
1 parent c3e1100 commit 3f42995
Show file tree
Hide file tree
Showing 16 changed files with 2,484 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Tizen.Core/Interop/Interop.Libraries.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2024 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
{
internal static partial class Libraries
{
public const string TizenCore = "libtizen-core.so.0";
}
}
331 changes: 331 additions & 0 deletions src/Tizen.Core/Interop/Interop.TizenCore.cs

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions src/Tizen.Core/Tizen.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Tizen.Log\Tizen.Log.csproj" />
<ProjectReference Include="..\Tizen\Tizen.csproj" />
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions src/Tizen.Core/Tizen.Core.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Core", "Tizen.Core.csproj", "{1BA08908-7B2B-42D1-A124-092CB177BF4C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen", "..\Tizen\Tizen.csproj", "{2E04FB0F-03F4-40B0-BB25-5ADFB08C8DF3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Log", "..\Tizen.Log\Tizen.Log.csproj", "{8DA5B43B-63E9-460C-B64F-0B691539DC5D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1BA08908-7B2B-42D1-A124-092CB177BF4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BA08908-7B2B-42D1-A124-092CB177BF4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BA08908-7B2B-42D1-A124-092CB177BF4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BA08908-7B2B-42D1-A124-092CB177BF4C}.Release|Any CPU.Build.0 = Release|Any CPU
{2E04FB0F-03F4-40B0-BB25-5ADFB08C8DF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E04FB0F-03F4-40B0-BB25-5ADFB08C8DF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E04FB0F-03F4-40B0-BB25-5ADFB08C8DF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E04FB0F-03F4-40B0-BB25-5ADFB08C8DF3}.Release|Any CPU.Build.0 = Release|Any CPU
{8DA5B43B-63E9-460C-B64F-0B691539DC5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8DA5B43B-63E9-460C-B64F-0B691539DC5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8DA5B43B-63E9-460C-B64F-0B691539DC5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8DA5B43B-63E9-460C-B64F-0B691539DC5D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E9B5E719-0EB7-430C-97DC-3FE2E50EE668}
EndGlobalSection
EndGlobal
105 changes: 105 additions & 0 deletions src/Tizen.Core/Tizen.Core/Channel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2024 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.Core
{
/// <summary>
/// The class for managing communication channels between tasks of Tizen Core.
/// </summary>
/// <since_tizen> 12 </since_tizen>
public class Channel : IDisposable
{
private bool _disposed = false;

/// <summary>
/// Constructor for creating a new channel with a sender and a receiver.
/// </summary>
/// <exception cref="OutOfMemoryException">Thrown when out of memory.</exception>
/// <example>
/// <code>
///
/// try
/// {
/// var channel = new Channel();
/// }
/// catch (OutOfMemoryException)
/// {
/// Console.WriteLine("Exception occurs");
/// }
///
/// </code>
/// </example>
/// <since_tizen> 12 </since_tizen>
public Channel()
{
Interop.LibTizenCore.ErrorCode error = Interop.LibTizenCore.TizenCoreChannel.MakePair(out IntPtr sender, out IntPtr receiver);
TCoreErrorFactory.CheckAndThrownException(error, "Failed to make a channel pair");
Sender = new ChannelSender(sender);
Receiver = new ChannelReceiver(receiver);
}

/// <summary>
/// Finalizer of the class Channel.
/// </summary>
~Channel()
{
Dispose(false);
}

/// <summary>
/// Gets the channel sender instance.
/// </summary>
/// <since_tizen> 12 </since_tizen>
public ChannelSender Sender { get; private set; }

/// <summary>
/// Gets the channel receiver instance.
/// </summary>
/// <since_tizen> 12 </since_tizen>
public ChannelReceiver Receiver { get; private set; }

/// <summary>
/// Release any unmanaged resources used by this object.
/// </summary>
/// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
/// <since_tizen> 12 </since_tizen>
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
Sender.Dispose();
Receiver.Dispose();
}

_disposed = true;
}
}

/// <summary>
/// Release any unmanaged resources used by this object.
/// </summary>
/// <since_tize> 12 </since_tize>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}
174 changes: 174 additions & 0 deletions src/Tizen.Core/Tizen.Core/ChannelObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
* Copyright (c) 2024 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.Concurrent;
using System.Runtime.InteropServices;

namespace Tizen.Core
{
/// <summary>
/// Represents a channel object used for inter-task communication.
/// </summary>
/// <since_tizen> 12 </since_tizen>
public class ChannelObject : IDisposable
{
private IntPtr _handle = IntPtr.Zero;
private bool _disposed = false;
private static readonly ConcurrentDictionary<int, object> _dataMap = new ConcurrentDictionary<int, object>();
private static readonly object _dataLock = new object();
private static int _dataId = 0;

/// <summary>
/// Constructor for creating a new channel object with specified ID and data.
/// </summary>
/// <param name="id">The ID.</param>
/// <param name="data">The data object.</param>
/// <exception cref="OutOfMemoryException">Thrown when out of memory.</exception>
/// <example>
/// <code>
///
/// int id = 0;
/// string message = "Test message";
/// var channelObject = new ChannelObject(id++, message);
///
/// </code>
/// </example>
/// <since_tizen> 12 </since_tizen>
public ChannelObject(int id, object data)
{
Interop.LibTizenCore.ErrorCode error = Interop.LibTizenCore.TizenCoreChannel.ObjectCreate(out _handle);
TCoreErrorFactory.CheckAndThrownException(error, "Failed to create channel object");
Id = id;
Data = data;
IsUsed = false;
}

internal ChannelObject(IntPtr handle)
{
_handle = handle;
IsUsed = false;
}

/// <summary>
/// Finalizer of the class ChannelObject.
/// </summary>
~ChannelObject()
{
Dispose(false);
}

/// <summary>
/// Gets and sets the ID.
/// </summary>
/// <since_tizen> 12 </since_tizen>
public int Id
{
get
{
Interop.LibTizenCore.TizenCoreChannel.ObjectGetId(_handle, out int id);
return id;
}
set
{
Interop.LibTizenCore.TizenCoreChannel.ObjectSetId(_handle, value);
}
}

/// <summary>
/// Gets and sets the data object.
/// </summary>
/// <since_tizen> 12 </since_tizen>
public object Data
{
get
{
Interop.LibTizenCore.TizenCoreChannel.ObjectGetData(_handle, out IntPtr handle);
int id = (int)handle;
if (_dataMap.TryGetValue(id, out var data))
{
return data;
}
return null;
}
set
{
int id;
lock (_dataLock)
{
id = _dataId++;
}
_dataMap[id] = value;
Interop.LibTizenCore.TizenCoreChannel.ObjectSetData(_handle, (IntPtr)id);
}
}

/// <summary>
/// Gets the name of the sender task.
/// </summary>
/// <since_tizen> 12 </since_tizen>
public string Sender {
get
{
Interop.LibTizenCore.TizenCoreChannel.ObjectGetSenderTaskName(_handle, out IntPtr taskName);
return Marshal.PtrToStringAnsi(taskName);
}
}

internal bool IsUsed { set; get; }

internal IntPtr Handle { get { return _handle; } }

/// <summary>
/// Release any unmanaged resources used by this object.
/// </summary>
/// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
/// <since_tizen> 12 </since_tizen>
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
if (_handle != IntPtr.Zero)
{
if (!IsUsed)
{
Interop.LibTizenCore.TizenCoreChannel.ObjectGetData(_handle, out IntPtr handle);
int id = (int)handle;
_dataMap.TryRemove(id, out var data);
}

Interop.LibTizenCore.TizenCoreChannel.ObjectDestroy(_handle);
_handle = IntPtr.Zero;
}
}

_disposed = true;
}
}

/// <summary>
/// Release any unmanaged resources used by this object.
/// </summary>
/// <since_tize> 12 </since_tize>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}
Loading

0 comments on commit 3f42995

Please sign in to comment.