// Copyright (c) 2013 Intel Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Implementation of the W3C's Device Capabilities API.
// http://www.w3.org/2012/sysapps/device-capabilities/

var internal = requireNative('internal');
internal.setupInternalExtension(extension);

var v8tools = requireNative('v8tools');
var common = requireNative('sysapps_common');
common.setupSysAppsCommon(internal, v8tools);

var Promise = requireNative('sysapps_promise').Promise;

var DeviceCapabilities = function() {
  common.BindingObject.call(this, common.getUniqueId());

  internal.postMessage("deviceCapabilitiesConstructor", [this._id]);

  this._addMethodWithPromise("getAVCodecs", Promise);
  this._addMethodWithPromise("getCPUInfo", Promise);
  this._addMethodWithPromise("getMemoryInfo", Promise);
  this._addMethodWithPromise("getStorageInfo", Promise);
};

DeviceCapabilities.prototype = new common.BindingObjectPrototype();
DeviceCapabilities.prototype.constructor = DeviceCapabilities;

exports = new DeviceCapabilities();

// Copyright (c) 2013 Intel Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Implementation of the W3C's Device Capabilities API.
// http://www.w3.org/2012/sysapps/device-capabilities/

var internal = requireNative('internal');
internal.setupInternalExtension(extension);

var v8tools = requireNative('v8tools');
var common = requireNative('sysapps_common');
common.setupSysAppsCommon(internal, v8tools);

var Promise = requireNative('sysapps_promise').Promise;

var DeviceCapabilities = function() {
  common.BindingObject.call(this, common.getUniqueId());
  common.EventTarget.call(this);

  internal.postMessage("deviceCapabilitiesConstructor", [this._id]);

  this._addEvent("storageattach");
  this._addEvent("storagedetach");

  this._addMethodWithPromise("getAVCodecs", Promise);
  this._addMethodWithPromise("getCPUInfo", Promise);
  this._addMethodWithPromise("getMemoryInfo", Promise);
  this._addMethodWithPromise("getStorageInfo", Promise);
};

DeviceCapabilities.prototype = new common.EventTargetPrototype();
DeviceCapabilities.prototype.constructor = DeviceCapabilities;

exports = new DeviceCapabilities();

Make the JavaScript shim dispatch events
[SysApps] Make the JavaScript shim dispatch events

The first thing to be done is make the JavaScript DeviceCapabilties an EventTarget
(which is also a BindingObject). The BindingObjects are JavaScripts objects with
a link with some native object and they use a unique ID for routing messages
between them.

common.EventTarget.call(this) initializes the EventTarget and makes
this._addEvent() possible.

Now all the blanks are filled and we are good to go. The next step would be
replace the StorageInfoProviderMock with a real implementation for each platform
we support. No need to touch on anything else.
