Permalink
Browse files

Refactor library to make it a bit cleaner

  • Loading branch information...
1 parent da83257 commit 7133e81e3a8cd1aa8862ea3d30f05450d74a26bc @Daniel15 committed Nov 26, 2011
View
@@ -0,0 +1,26 @@
+using System;
+using DBus;
+using NTelepathy.Dbus;
+
+namespace NTelepathy
+{
+ /// <summary>
+ /// Telepathy Account interface. Handles account details.
+ /// </summary>
+ /// <remarks>Reference: http://telepathy.freedesktop.org/spec-0.20/Account.html</remarks>
+ public abstract class Account : DbusBase, IAccount
+ {
+ /// <summary>
+ /// Gets the connection for this account
+ /// </summary>
+ public ISimplePresence Connection
+ {
+ get
+ {
+ ObjectPath path = GetProperty<ObjectPath>(Constants.ACCOUNT_INTERFACE, "Connection");
+ return DbusHelper.GetWithProperties<Connection>(NTelepathy.Connection.BusName(path), path);
+ }
+ }
+ }
+}
+
View
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using DBus;
+using NTelepathy.Dbus;
+
+namespace NTelepathy
+{
+ /// <summary>
+ /// Telepathy AccountManager interface. Handles management of accounts.
+ /// </summary>
+ /// <remarks>Reference: http://telepathy.freedesktop.org/spec-0.20/Account_Manager.html</remarks>
+ public abstract class AccountManager : DbusBase, IAccountManager
+ {
+ /// <summary>
+ /// Get all the valid accounts this account manager knows about
+ /// </summary>
+ /// <value>The accounts</value>
+ public IEnumerable<IAccount> ValidAccounts
+ {
+ get
+ {
+ ObjectPath[] paths = GetProperty<ObjectPath[]>(Constants.ACCOUNTMANAGER_INTERFACE, "ValidAccounts");
+ return DbusHelper.GetWithProperties<Account>(Constants.ACCOUNTMANAGER_BUS, paths);
+ }
+ }
+ }
+}
+
View
@@ -0,0 +1,36 @@
+using System;
+using DBus;
+
+namespace NTelepathy
+{
+ /// <summary>
+ /// Telepathy connection interface.
+ /// </summary>
+ /// <remarks>Reference: http://telepathy.freedesktop.org/spec-0.20/Connection.html</remarks>
+ public abstract class Connection : DbusBase, IConnection, ISimplePresence
+ {
+ /// <summary>
+ /// Sets the current presence
+ /// </summary>
+ /// <param name='status'>Status (eg. "available", "busy")</param>
+ /// <param name='statusMessage'>Status message</param>
+ public abstract void SetPresence (string status, string statusMessage);
+
+ /// <summary>
+ /// Gets the bus name for the specified connection manager object path
+ /// </summary>
+ /// <returns>The bus name</returns>
+ /// <param name='objectPath'>The object path</param>
+ public static string BusName(ObjectPath objectPath)
+ {
+ // TODO: Is there a better (proper?) way to do this?
+
+ // ObjectPath is eg. /org/freedesktop/Telepathy/Connection/gabble/jabber/daniel_40d15_2ebiz_2f3e9348f3
+ // Connection manager type is 5th item (eg. "gabble")
+ string connType = objectPath.ToString().Split('/')[5];
+
+ return string.Format("org.freedesktop.Telepathy.ConnectionManager.{0}", connType);
+ }
+ }
+}
+
@@ -1,24 +0,0 @@
-using DBus;
-
-namespace NTelepathy.Dbus
-{
- /// <summary>
- /// Properties for AccountManager interface
- /// </summary>
- /// <remarks>Reference: http://telepathy.freedesktop.org/spec-0.20/Account_Manager.html</remarks>
- public abstract class AccountManagerProperties : PropertiesBase
- {
- /// <summary>
- /// Get all the valid accounts this account manager knows about
- /// </summary>
- /// <value>The accounts</value>
- public ObjectPath[] ValidAccounts
- {
- get
- {
- return (ObjectPath[])Get(Constants.ACCOUNTMANAGER_INTERFACE, "ValidAccounts");
- }
- }
- }
-}
-
View
@@ -1,24 +0,0 @@
-using DBus;
-
-namespace NTelepathy.Dbus
-{
- /// <summary>
- /// Properties for the Account interface
- /// </summary>
- /// <remarks>Reference: http://telepathy.freedesktop.org/spec-0.20/Account.html</remarks>
- public abstract class AccountProperties : PropertiesBase
- {
- /// <summary>
- /// Gets the path to the connection for this account
- /// </summary>
- /// <value>The connection</value>
- public ObjectPath Connection
- {
- get
- {
- return (ObjectPath)Get(Constants.ACCOUNT_INTERFACE, "Connection");
- }
- }
- }
-}
-
View
@@ -23,6 +23,8 @@ public abstract class Constants
/// Interface for accounts.
/// </summary>
public const string ACCOUNT_INTERFACE = "org.freedesktop.Telepathy.Account";
+
+ public const string SIMPLEPRESENCE_INTERFACE = "org.freedesktop.Telepathy.Connection.Interface.SimplePresence";
}
}
View
@@ -0,0 +1,36 @@
+using System;
+using System.Reflection;
+using DBus;
+using org.freedesktop.DBus;
+using NTelepathy;
+
+namespace NTelepathy
+{
+ public abstract class DbusBase
+ {
+ public Properties Properties { get; set; }
+
+ /*protected string Interface
+ {
+ get
+ {
+ InterfaceAttribute attrib = (InterfaceAttribute)Attribute
+ .GetCustomAttribute(GetType(), typeof(InterfaceAttribute), true);
+
+ return attrib.Name;
+ }
+ }*/
+
+ protected T GetProperty<T>(string @interface, string name)
+ {
+ return (T)Properties.Get(@interface, name);
+ }
+
+ protected T GetProperty<T>(string @interface, string name, string bus_name) where T : DbusBase
+ {
+ ObjectPath path = GetProperty<ObjectPath>(@interface, name);
+ return DbusHelper.GetWithProperties<T>(bus_name, path);
+ }
+ }
+}
+
View
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using DBus;
+using org.freedesktop.DBus;
+
+namespace NTelepathy
+{
+ public static class DbusHelper
+ {
+ public static T GetWithProperties<T>(string bus_name, ObjectPath path) where T : DbusBase
+ {
+ T obj = Bus.Session.GetObject<T>(bus_name, path);
+ Properties props = Bus.Session.GetObject<Properties>(bus_name, path);
+ obj.Properties = props;
+ return obj;
+ }
+
+ public static IEnumerable<T> GetWithProperties<T>(string bus_name, ObjectPath[] paths) where T : DbusBase
+ {
+ IList<T> results = new List<T>(paths.Length);
+
+ foreach (ObjectPath path in paths)
+ {
+ results.Add(GetWithProperties<T>(bus_name, path));
+ }
+
+ return results;
+ }
+ }
+}
+
View
@@ -1,17 +0,0 @@
-using System.Collections.Generic;
-
-namespace NTelepathy.Dbus
-{
- /// <summary>
- /// Base class for all properties classes
- /// </summary>
- public abstract class PropertiesBase : org.freedesktop.DBus.Properties
- {
- // Below three methods are from Properties interface. They are
- // implemented by the DBus proxy classes.
- public abstract object Get (string @interface, string propname);
- public abstract void Set (string @interface, string propname, object value);
- public abstract IDictionary<string, object> GetAll (string @interface);
- }
-}
-
View
@@ -0,0 +1,20 @@
+using System;
+using DBus;
+using NTelepathy.Dbus;
+
+namespace NTelepathy
+{
+ /// <summary>
+ /// Telepathy Account interface. Handles account details.
+ /// </summary>
+ /// <remarks>Reference: http://telepathy.freedesktop.org/spec-0.20/Account.html</remarks>
+ [Interface(Constants.ACCOUNT_INTERFACE)]
+ public interface IAccount
+ {
+ /// <summary>
+ /// Gets the connection for this account
+ /// </summary>
+ ISimplePresence Connection { get; }
+ }
+}
+
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using DBus;
+using NTelepathy.Dbus;
+
+namespace NTelepathy
+{
+ /// <summary>
+ /// Telepathy AccountManager interface. Handles management of accounts.
+ /// </summary>
+ /// <remarks>Reference: http://telepathy.freedesktop.org/spec-0.20/Account_Manager.html</remarks>
+ [Interface(Constants.ACCOUNTMANAGER_INTERFACE)]
+ public interface IAccountManager
+ {
+ /// <summary>
+ /// Get all the valid accounts this account manager knows about
+ /// </summary>
+ /// <value>The accounts</value>
+ IEnumerable<IAccount> ValidAccounts { get; }
+ }
+}
+
View
@@ -0,0 +1,13 @@
+using System;
+
+namespace NTelepathy
+{
+ /// <summary>
+ /// Telepathy connection interface.
+ /// </summary>
+ /// <remarks>Reference: http://telepathy.freedesktop.org/spec-0.20/Connection.html</remarks>
+ public interface IConnection
+ {
+ }
+}
+
@@ -1,14 +1,15 @@
using System;
+using NTelepathy.Dbus;
using DBus;
-namespace NTelepathy.Dbus
+namespace NTelepathy
{
/// <summary>
/// Telepathy SimplePresence interface
/// </summary>
/// <remarks>Reference: http://telepathy.freedesktop.org/spec-0.20/Connection_Interface_Simple_Presence.html</remarks>
- [Interface("org.freedesktop.Telepathy.Connection.Interface.SimplePresence")]
- public interface ISimplePresence
+ [Interface(Constants.SIMPLEPRESENCE_INTERFACE)]
+ public interface ISimplePresence : IConnection
{
/// <summary>
/// Sets the current presence
@@ -0,0 +1,27 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes.
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("NTelepathy.Example")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("daniel")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("1.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly,
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+
View
@@ -0,0 +1,17 @@
+using System;
+
+namespace NTelepathy.Example
+{
+ class MainClass
+ {
+ public static void Main (string[] args)
+ {
+ AccountManager manager = Telepathy.AccountManager;
+
+ foreach (Account account in manager.ValidAccounts)
+ {
+ account.Connection.SetPresence("available", "Hello World");
+ }
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 7133e81

Please sign in to comment.