view dbus-d-javatests/jsrc/filetree/DataItem.d @ 0:a5576806d36d

recreate repository without any libs for lightweight repository
author Frank Benoit <benoit@tionex.de>
date Sat, 20 Oct 2007 18:07:18 +0200
parents
children
line wrap: on
line source

/*
 * Generated with TioLink
 * TioLink was written by Frank Benoit <benoit@tionex.de>
 * http://www.dsource.org/projects/tiolink
 *
 * User specific code can be place after the generated comment line containing:
 * "USER CONTENT STARTS HERE".
 * Everything before that line will be programmatically overwritten.
 *
 * File type: D programming language source code
 */
module filetree.DataItem;

import org.freedesktop.dbus.DBus;
import org.freedesktop.dbus.Introspectable;

// Interface for DataItem

interface DataItem : org.freedesktop.dbus.DBusInterface.DBusInterface {
    public filetree.DataItem.DataItem[] getChilds();
    public bool isFolder();
    public bool isDrive();
    public char[] getName();
    const static char[] introspectionXml = 
        `<interface name="filetree.DataItem"/>`\n
        `  <method name="getChilds">`\n
        `    <arg name="p0" type="ao" direction="out"/>`\n
        `  </method>`\n
        `  <method name="isFolder">`\n
        `    <arg name="p0" type="b" direction="out"/>`\n
        `  </method>`\n
        `  <method name="isDrive">`\n
        `    <arg name="p0" type="b" direction="out"/>`\n
        `  </method>`\n
        `  <method name="getName">`\n
        `    <arg name="p0" type="s" direction="out"/>`\n
        `  </method>`\n
        `</interface>`\n
        ;
}

CConnection.DBusHandlerResult intfHandler__filetree_DataItem_DataItem( CConnection.DBusConnection* conn, CConnection.DBusMessage* message, void* user_data ){
    DataItem o = cast(DataItem)cast(Object)user_data;
    if( o is null || !checkIntf( "filetree.DataItem", message) )
        return CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    
    try{
        char[METHOD_SIG_MAXLENGTH] buf;
        switch( methodSignature( message, buf ) ){
        case "getChilds|":
            {
                filetree.DataItem.DataItem[] callResult = o.getChilds();
                sendReply( conn, message, callResult );
            }
            break;
        case "isFolder|":
            {
                bool callResult = o.isFolder();
                sendReply( conn, message, callResult );
            }
            break;
        case "isDrive|":
            {
                bool callResult = o.isDrive();
                sendReply( conn, message, callResult );
            }
            break;
        case "getName|":
            {
                char[] callResult = o.getName();
                sendReply( conn, message, callResult );
            }
            break;
        default:
            return CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
        }
    }
    catch( Exception e ){
        sendException( conn, message, e );
    }
    return CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED;
}
void intfFree__filetree_DataItem_DataItem( CConnection.DBusConnection *connection, void *user_data ){
}


// Dimpl for MyDataItem

extern(C) CConnection.DBusHandlerResult dimplHandler__filetree_DataItem_MyDataItem( CConnection.DBusConnection* conn, CConnection.DBusMessage* message, void* user_data ){
    CConnection.DBusHandlerResult res = CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    if( res == CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED ){
        res = intfHandler__filetree_DataItem_DataItem( conn, message, user_data );
    }
    if( res == CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED ){
        res = intfHandler__org_freedesktop_dbus_Introspectable_Introspectable( conn, message, user_data );
    }
    return res;
}

extern(C) void dimplFree__filetree_DataItem_MyDataItem( CConnection.DBusConnection *connection, void *user_data ){
}

CConnection.DBusObjectPathVTable vtable__filetree_DataItem_MyDataItem = {
    unregister_function : & dimplFree__filetree_DataItem_MyDataItem,
    message_function    : & dimplHandler__filetree_DataItem_MyDataItem
};


static assert( is( MyDataItem : filetree.DataItem.DataItem ));
static assert( is( MyDataItem : org.freedesktop.dbus.Introspectable.Introspectable ));

// --- USER CONTENT STARTS HERE (do not change this marker line) ---

import tango.core.Exception;
import tango.io.Stdout;
import tango.io.FilePath;

class MyDataItem : DBusObject, DataItem, Introspectable {
	FilePath file;

	public this( FilePath absPath ){
		super( this.classinfo );
		file = absPath;
		//Stdout.formatln( "{} {} {}", __LINE__, __FILE__, file.toUtf8() );
	}
		
	public char[] Introspect(){
		return buildIntrospect( [DataItem.introspectionXml, Introspectable.introspectionXml ], null );
	}
	public DBusObjectPathVTable* getDBusVTable(){
		return &vtable__filetree_DataItem_MyDataItem;
	}
	public DataItem[] getChilds(){
		//Stdout.formatln( "{} {} ", __LINE__, __FILE__ );
		char[][] names;
		try{
            int      i;
            char[][] list;
            void add (char[] path, char[] name, bool dir) {
            	if( name == "." || name == ".." ){
            		return;
            	}
                if (i >= list.length)
                    list.length = list.length * 2;
                
                list[i++] = path~name;
            }
            list = new char[][512];
            file.toList (&add);
            names = list [0 .. i];
		} catch( IOException e ){
			// nothing happends
		}

		//Stdout.formatln( "{} {} ", __LINE__, __FILE__ );
		DataItem[] res = new DataItem[ names.length ];
		//Stdout.formatln( "{} {} ", __LINE__, __FILE__ );
		for( int i = 0; i < names.length; i++ ){
			char[] path = names[i];
			//Stdout.formatln( "{} {} {}", __LINE__, __FILE__, path );
			res[i] = new MyDataItem( new FilePath( path ) );
		}
		//Stdout.formatln( "{} {} ", __LINE__, __FILE__ );
		return res;
	}
	public char[] getName(){
		return file.file();
	}
	public bool isFolder(){
		//Stdout.formatln( "{} {} {}", __LINE__, __FILE__, file.toUtf8() );
		bool res = false;
		try{
			res = file.isFolder();
		} catch( IOException e ){
		}
		return res;
	}
	
	public bool isDrive(){
		Stdout.formatln( "{} {} ", __LINE__, __FILE__ );
		return false;
	}
	public override char[] toUtf8(){
		return file.toUtf8();
	}
}