AIR for TV extension examples

Adobe® AIR® for TV provides several examples of native extensions. The native implementation is written in C++ and uses the AIR for TV extensions development kit (EDK). The EDK is distributed to device manufacturers and system-on-a-chip manufacturers who include AIR for TV with their product. More information about the AIR for TV EDK and creating AIR for TV extensions is in Building an AIR for TV native extension .

As an AIR for TV extension developer, you can:

  • Copy these examples as starting point for your extension.

  • See these examples for code samples that show how to use various C API extension functions as well as the ActionScript ExtensionContext class.

  • Copy the makefile of one of these examples as a starting point for creating the makefile for your extension.

HelloWorld example

The HelloWorld example is in the following directory of the AIR for TV distribution:

<AIR for TV installation directory>/products/stagecraft/source/ae/edk/helloworld
The HelloWorld example is a simple extension to illustrate basic extension behavior. It does the following:
  • Uses the ExtensionContext.call() method to pass a string from the ActionScript side to the native implementation.

  • Returns a string from the native implementation to the ActionScript side.

  • Starts a thread in the native implementation that sends asynchronous events to the ActionScript side.

The following table describes each file and its location relative to the helloworld/ directory:

File

Description

HelloWorld.as

in directory

as/device/src/tv/adobe/extension/example/

ActionScript side of the real (not the stub) extension that defines the HelloWorld class. It does the following:

  • Creates an ExtensionContext instance.

  • Defines the extension’s ActionScript APIs: Hello() and StartCount() .

  • Listens for events on the ExtensionContext instance, and redispatches the events to the HelloWorld instance’s listeners.

HelloWorld.as

in directory

as/distributable/src/tv/adobe/extension/example/

ActionScript of the stub extension that defines the HelloWorld class. This ActionScript-only stub defines the extension’s ActionScript APIs: Hello() and StartCount() . However, the stub implementations do not call native functions.

HelloWorldExtensionClient.as

in directory

client/src

AIR application that uses the extension. The AIR application is the client of the extension. It does the following:

  • Creates an instance of the HelloWorld class.

  • Listens for events on the HelloWorld instance.

  • Calls the HelloWorld instance’s Hello() and StartCount() APIs.

HelloWorldExtensionClient-app.xml

in directory

client/src

AIR application descriptor file. Includes the <extensions> element with the extensionID value tv.adobe.extension.example.HelloWorld .

HelloWorld.h

in directory

native/

The C++ header file of the HelloWorld class.

HelloWorld.cpp

in directory

native/

The C++ implementation file of the HelloWorld class. The implementation does the following:

  • Defines the FREFunction Hello() which writes its string parameter to the console. It also returns the string “Hello from extensionland”.

  • Defines the FREFunction StartCount() which starts an asynchronous thread to send one event every 500 milliseconds to the ExtensionContext instance.

HelloWorldExtension.cpp

in directory

native/

Contains implementations of the following C API extension functions:

  • FREInitializer()

  • FREContextInitializer()

  • FREContextFinalizer()

  • FREFinalizer()

PlatformEDKExtension_HelloWorld.mk

The makefile for the HelloWorld extension.

ExtensionUtil.h

in directory

<AIR for TV installation directory> /products/stagecraft/source/ae/edk

Contains macros convenient to coding your C or C++ implementation.

ExtensionBridge.cpp

in directory

<AIR for TV installation directory> /products/stagecraft/source/ae/edk

The AIR for TV extension module implementation. When you build your native implementation, include this source file in your build.

phonyEdkAneCert.p12

in directory

<AIR for TV installation directory> /products/stagecraft/source/ae/edk

A phony certificate that the make utility uses for packaging the HelloWorld extension into an ANE file.

extension.mk

in directory

<AIR for TV installation directory> /products/stagecraft/source/ae/edk

The makefile for the extension module. Do not modify this file.

Process example

The Process example is in the following directory of the AIR for TV distribution:

<AIR for TV installation directory>/products/stagecraft/source/ae/edk/process

The Process extension allows an AIR application to manipulate Linux processes, including the following functionality:

  • Spawning a Linux process. The process executes a Linux command that the AIR application specifies.

  • Getting the process identifier of the process.

  • Checking whether the process has completed.

  • Receiving an event that the process has completed.

  • Getting the return code from the completed process.

  • Receiving events indicating that the process has written to stdout or stderr .

  • Retrieving the output strings from stdout and stderr .

  • Writing strings to stdin .

  • Sending an interrupt signal to the process.

  • Killing the process.

The following table describes each file and its location relative to the process/ directory:

File

Description

Process.as

in directory

as/device/src/tv/adobe/extension/process/example/

ActionScript side of the real (not the stub) extension that defines the Process class. It does the following:

  • Creates an ExtensionContext instance.

  • Defines the extension’s ActionScript APIs.

  • Listens for events on the ExtensionContext instance, and redispatches the events to the Process instance’s listeners.

ProcessEvent.as

in directory

as/device/src/tv/adobe/extension/process/example/

Defines the ProcessEvent class, which derives from the Event class.

The AIR application ActionScript listens for these ProcessEvent notifications.

Process.as

in directory

as/distributable/src/tv/adobe/extension/process/example/

ActionScript of the stub extension that defines the Process class. This ActionScript-only stub defines the extension’s ActionScript APIs. However, the stub implementations do not call native functions.

ProcessExtensionClient.as

in directory

client/simple/src

AIR application that uses the extension. The AIR application is the client of the extension. It provides an example of how an AIR application uses the Process extension APIs.

ProcessExtensionClient-app.xml

in directory

client/simple/src

AIR application descriptor file. Includes the <extensions> element with the extensionID value tv.adobe.extension.process.Process .

Process.h

in directory

native/

The C++ header file of the abstract Process class.

ProcessLinux.h

in directory

native/

The C++ header file of the concrete ProcessLinux class.

The ProcessLinux class derives from the Process class. It declares private methods and data for a Linux implementation of the Process class.

ProcessLinux.cpp

in directory

native/

The C++ implementation file of the ProcessLinux class. The implementation includes the following functionality:

  • Defines the FREFunction functions. These functions use Linux system calls to, for example, fork and exec a Linux process and to interact with stdin , stdout , and stderr

  • Monitors the status of the spawned process. The implementation creates a thread for this purpose. The thread uses the C extension API FREDispatchStatusEventAsync() to report events.

  • Defines helper functions for creating FREObject variables for returning information from the FREFunction functions to the ActionScript side. These helper functions use C API extension functions such as FRENewObjectFromBool() , FRENewObjectFromUTF8() , and FRENewObjectFromUint32() .

ProcessExtension.cpp

in directory

native/

Contains implementations of the following C API extension functions:

  • FREInitializer()

  • FREContextInitializer()

  • FREContextFinalizer()

  • FREFinalizer()

PlatformEDKExtension_Process.mk

The makefile for the Process extension.

ExtensionUtil.h

in directory

<AIR for TV installation directory> /products/stagecraft/source/ae/edk

Contains macros convenient to coding your C or C++ implementation.

ExtensionBridge.cpp

in directory

<AIR for TV installation directory> /products/stagecraft/source/ae/edk

The AIR for TV extension module implementation. When you build your native implementation, include this source file in your build.

phonyEdkAneCert

in directory

<AIR for TV installation directory> /products/stagecraft/source/ae/edk

A phony certificate that the make utility uses for packaging the Process extension into an ANE file.

extension.mk

in directory

<AIR for TV installation directory> /products/stagecraft/source/ae/edk

The makefile for the extension module. Do not modify this file.

Build the extension examples on the x86Desktop platform

To build the Hello World or Process extension example on the x86Desktop platform, first build your AIR for TV distribution for the x86Desktop platform. Instructions are in Getting Started with Adobe AIR for TV (PDF) in Quick Start on Linux .

Note: Make sure that you installed the AIR 3 SDK, the The Open Source Flex® SDK, and the Java™ runtime, and included the bin directories in your PATH environment variable. Building native extensions for AIR for TV depends on these libraries.

Next, add building the Hello World or Process extension example to your x86Desktop build. Do the following:

  1. Change to the directory:

    <AIR for TV installation directory>/products/stagecraft/build/linux/platforms/x86Desktop
  2. Link to the .mk file of the extension you want to build. For example:

    ln -s <AIR for TV installation directory>/products/stagecraft/source/ae/edk/helloworld/PlatformEDKExtension_HelloWorld.mk
  3. Change to the directory:

     <AIR for TV installation directory>/products/stagecraft/build/linux
  4. Build the distribution, including the extension example:

    make

    Alternatively, build only the extension example. For example:

    make PlatformEDKExtension_HelloWorld.mk

The make utility creates two files for each extension example. It puts the files in one of the following directories depending on whether you specified debug or release for SC_BUILD_MODE :

<AIR for TV installation directory>/build/stagecraft/linux/x86Desktop/debug/bin  
<AIR for TV installation directory>/build/stagecraft/linux/x86Desktop/release/bin

The files that the make utility creates for the example extension are:

  • A ZIP file that contains the device-bundled extension.

  • An ANE file that contains the stub or simulator extension.

// Ethnio survey code removed