2011年8月 のアーカイブ

Adobe Digital Enterprise Platform ( ADEP )

2011年8月18日

ADEP in detail
ADEP Architecture
Customer Experience Management
Document Services
Experience Services

Featured Engineering videos
Installing the ADEP Experience Server
Installing additional functionality using package share
Installing and configuring Experience Services/RIA Tooling
Exploring the Out of Box Experience Server Samples
Mobile application development on ADEP (Part 1)
Mobile application development on ADEP (Part 2)
Converting an existing Flex Project into an ADEP Experience Services project
Converting an existing Flex application into a composite application tile
http://www.youtube.com/user/ADEPDevelopers

Samples
Experience Services Samples
Document Services Application Samples

trial downloads
server
tools

government,politics news,politics news,politics

AIR 3 Native Extension 13 Try AIR for Android + ANE in Java

2011年8月16日

前回までで、WindowsとiOSのANEはできました、今回は、ANE を使ってAIR for Androidを拡張します。

1. Java Projectでjar開発準備
EclipseでJavaプロジェクトを作成します。
プロジェクト名は、HelloWorldANEです。

プロジェクトが生成されたら
AIR 3 HOME/lib/android/FlashRuntimeExtensions.jar
をビルドパスに設定します。

準備完了

2. HelloWorldANE.javaクラスを作成
Native Extensionとして登録するクラスは、com.adobe.fre.FREExtensionインターフェイスを実装します。

package net.akb7.android.ane;

import java.util.HashMap;
import java.util.Map;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREExtension;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
import com.adobe.fre.FREWrongThreadException;

public class HelloWorldANE implements FREExtension {
    public FREContext createContext(String arg) {
        FREContext context = new FREContext() {
                ...
        };

        return context;
    }

    public void initialize() {
    }

    public void dispose() {
    }
}

コンテキストは、com.adobe.fre.FREContextを実装します。

@Override
FREContext context = new FREContext() {
    @Override
    public Map<String, FREFunction> getFunctions() {
        Log.i("HelloWorldANE$FREContext", "getFunctions");
        HashMap<String, FREFunction> result = new HashMap<String, FREFunction>();
        result.put("SayHello", new FREFunction() {
            ...
        });

        return result;
    }

    @Override
    public void dispose() {
        Log.i("HelloWorldANE$FREContext", "dispose");
    }
};

Netive Extension用の関数は、com.adobe.fre.FREFunctionを実装します。
callの中にロジックを記述します。

new FREFunction() {
    @Override
    public FREObject call(FREContext arg0, FREObject[] arg1) {
        try {
            return FREObject.newObject("Hello World");
        } catch (FREWrongThreadException e) {
            e.printStackTrace();
            return null;
        }
    }
}

3. コンパイルからのJarを作成
Java Projectをクリーンして、右クリックしてエクスポートからJarをエクスポートします。

4. ANE作成
基本的には、ここを参照してください
Windows版とことなるのは、AIR extension descriptor fileです。

initializer/finalizerには、FREExtensionを実装したクラスを指定します。

<extension xmlns="http://ns.adobe.com/air/extension/2.5">
    <id>nativeExtension</id>
    <versionNumber>1.0.0</versionNumber>
    <platforms>
        <platform name="Android-ARM">
            <applicationDeployment>
                <nativeLibrary>HelloWorldANE.jar</nativeLibrary>
                <initializer>FREExtensionを実装したクラス</initializer>
                <finalizer>FREExtensionを実装したクラス</finalizer>
            </applicationDeployment>
        </platform>
    </platforms>
</extension>

5. AIR for Androidアプリ開発
AIR for AndroidをADTでコマンドラインでコンパイルすればextdirを指定できるので
Windows版と同様にAIR for AndroidでもANEを使えることになります。

government,politics news,politics news,politics

AIR 3 Native Extension 12 Try Develop Async Event in C

2011年8月15日

今回は非同期処理を使ってネイティブライブラリからステートイベントを発行します。

1. 非同期版GetHelloWorld関数実装
GetHelloWorldはスレッドを実行して1を返すようにします。
スレッドは、_beginthreadを使います。
contextは、スレッド内で必要なのでグローバル変数に保持します。

また、起動したスレッドの処理(work_thread)では、1秒待機して
イベントを発行しています。

Native ExtensionのAPIは、ここを参照してください。

FREContext context;

void __cdecl work_thread(void* param) {
    _sleep(1000);
    const uint8_t* msg1 = (const uint8_t*)"Hello World";
    const uint8_t* msg2 = (const uint8_t*)"Message";
    FREDispatchStatusEventAsync(context,msg1,msg2);
    context = NULL;
}

FREObject GetHelloWorld(FREContext ctx, void*
    funcData, uint32_t argc, FREObject argv[]
)
{
	context = ctx;
	_beginthread(work_thread, 0, NULL);

	FREObject retObj;
	FRENewObjectFromInt32(1, &retObj);
	return retObj;
}

2. コンテキストのステートイベントをハンドルします。
StatusEvent.STAUSをハンドリングします。

        public function HelloWorldExtension()
        {
            context = ExtensionContext.createExtensionContext("nativeExtension", "type");
            context.addEventListener(StatusEvent.STATUS,eventHandler);
        }

        protected function eventHandler(event:Event):void{
            trace(event);
            dispatchEvent( event );
        }

今回は、Windows版のCでスレッドを起動させて非同期処理を行いステータスイベントを発行してみました。
Native Extensionを使うと非同期処理も扱えます。

参考資料
マルチスレッド
Visual C++ .NET または Visual C++ 2005 でスレッドを作成する方法
MSDN _beginthread、_beginthreadex

government,politics news,politics news,politics

AIR 3 Native Extension 7 Try Develop HelloWorld ANE SWC

2011年8月14日

前回は、HellowWorldという文字列返す関数を定義してNative Extensionで使えるような定義をしたDLLを作成しました。

今回は、ANE-SWCをつくりましょう。
ANE-SWCとは、ANEを作成するときに必要になるSWCです。
基本的にこのSWCの中に、DLLなどで作ったNative Extensionを呼び出すためのクラスを入れます。

1. Native Extensionを呼び出すクラス
前回作ったNative ExtensionのGetHelloWorld関数を呼び出す簡単なクラスです。
コンパイルしてSWCを作っておきます。

package net.akb7.air.extension
{
    import flash.external.ExtensionContext;

    public class HelloWorldExtension
    {
        private var context:ExtensionContext;

        public function HelloWorldExtension() {
            //nativeExtensionというextensionIDで取得できるNative Extensionのコンテキストを取得
            context = ExtensionContext.createExtensionContext("nativeExtension", "type");
        }

        public function GetHelloWorld() : String {
            //コンテキストにGetHelloWorldという名前で登録されている関数を呼び出します。
            return "> "+context.call("GetHelloWorld") as String;
        }

        public function dispose() : void {
            return context.dispose();
        }
    }
}

2. AIR extension descriptor fileを作成
Native Extensionの説明を書きます。
nativeLibrary
前回作ったNative ExtensionのDLLのパス

initializer
ここでNative Extensionの初期化時の関数を定義します。
nativeLibraryで指定したDLLから文字列で検索するためにC言語形式の関数にする必要あり。

<extension xmlns="http://ns.adobe.com/air/extension/2.5">
    <id>nativeExtension</id>
    <versionNumber>1.0.0</versionNumber>
    <platforms>
        <platform name="Windows-x86">
            <applicationDeployment>
                <nativeLibrary>HelloWorldExtension.dll</nativeLibrary>
                <initializer>ExtInitializer</initializer>
                <finalizer>ExtFinalizer</finalizer>
            </applicationDeployment>
        </platform>
    </platforms>
</extension>

3. ANE生成
下記のようなADTコマンドでANEができあがります。
ANEを配布するときはAIRのコードサイニング証明書を使うべきです。

ane作成用のADTオプションについてはここを参照

例1) カレントフォルダに必要ファイルを置いている場合 ファイル指定

adt
-package
-storetype pkcs12 -keystore test.p12
-target ane HelloWorldExtension.ane extension.xml
-swc bin\HelloWorldExtensionANE.swc
-platform Windows-x86 library.swf HelloWorldExtension.dll

例2) platform¥win配下に必要ファイルを置いている場合 ファイル指定

adt
-package
-storetype pkcs12 -keystore test.p12
-target ane HelloWorldExtension.ane extension.xml
-swc bin\HelloWorldExtensionANE.swc
-platform Windows-x86 -C platform\win library.swf HelloWorldExtension.dll

例3) platform¥win配下に必要ファイルを置いている場合 ディレクトリ指定

adt
-package
-storetype pkcs12 -keystore test.p12
-target ane HelloWorldExtension.ane extension.xml
-swc bin\HelloWorldExtensionANE.swc
-platform Windows-x86 -C platform\win .

できあがった、HelloWorldExtension.aneを次回つかいます。

4. ANEの中身
ANEのMIMEは、application/vnd.adobe.air-native-extension-package+zip です。
ANEは、ZIP形式です。解凍してみましょう。
SWC+Native Extensionって感じです。

- catalog.xml
- library.swf
- mimetype
+ META-INF
– signatures.xml
-+ ANE
— extension.xml
–+ Windows-x86
—- HelloWorldExtension.dll
—- library.swf

参考URL
ネイティブ拡張パッケージの作成
http://help.adobe.com/ja_JP/air/extensions/WSf268776665d7970d-2482335412ffea65006-8000.html

government,politics news,politics news,politics

AIR 3 Native Extension 11 Try Develop ANE in C# D

2011年8月12日

前回は、iOS用のANEをObjective-Cで作りました。
今回は、またWindowsに戻りましてC#で作ったクラスをANE化してみましょう!

1. C#でDLLを作成
Visual Studio 2010 C# のクラスライブラリプロジェクトですぐ作れますね。
DLLは、CSHelloWorld.dll にします。

using System;

namespace CSHellowWorld
{
    public class HelloWorldFactory
    {
        public String GetString()
        {
            return "HelloWorld";
        }
    }
}

2. C++でC#で作ったDLLのクラスを使う
前回のHelloWorldで使ったC++プロジェクトを使います。6を参照
C++プロジェクトにCSHelloWorld.dllを参照を追加します。
また、C#のSystem.dllも参照を追加します。

参照に追加したので、#usingを使って定義を読み込むことが出来ます。
そして、using namespaceで使用する名前空間を指定します。

#using <mscorlib.dll>
#using "CSHellowWorld.dll"

using namespace System;
using namespace System::Runtime::InteropServices;
using namespace CSHellowWorld;

...

FREObject GetHelloWorld(
    FREContext ctx,
    void* funcData,
    uint32_t argc,
    FREObject argv[]
) {
    const uint8_t* msg = (const uint8_t*)"Hello World";

    HelloWorldFactory^ f = gcnew HelloWorldFactory();
    String^ str = f->GetString();

    IntPtr mptr = Marshal::StringToHGlobalAnsi(str);
    const char* msg = static_cast<const char*>(mptr.ToPointer());

    FREObject retObj;
    FRENewObjectFromUTF8(strlen((const char*)msg)+1, (const uint8_t *)msg, &retObj);

    Marshal::FreeHGlobal(mptr);

    return retObj;
}

3. コンパイル & ANE作成
コンパイルとANE作成は、を参照

4. 実行時の注意
デバック実行やパッケージについては、8を参照
CSHelloWorld.dllをAIRアプリケーションのルートに配置します。
これによって、ANE DLLが参照しているCSHelloWorld.dllを解決することができます。

これでC#でもNative Extensionが作れるということになります。

参考資料
ネイティブと .NET の相互運用性

government,politics news,politics news,politics