15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/private/flash_message_loop.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/c/pp_errors.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/c/private/ppb_flash_message_loop.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/instance_handle.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/module_impl.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace pp {
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)template <> const char* interface_name<PPB_Flash_MessageLoop>() {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return PPB_FLASH_MESSAGELOOP_INTERFACE;
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace flash {
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MessageLoop::MessageLoop(const InstanceHandle& instance) {
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (has_interface<PPB_Flash_MessageLoop>()) {
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PassRefFromConstructor(get_interface<PPB_Flash_MessageLoop>()->Create(
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        instance.pp_instance()));
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MessageLoop::~MessageLoop() {
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool MessageLoop::IsAvailable() {
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return has_interface<PPB_Flash_MessageLoop>();
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int32_t MessageLoop::Run() {
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!has_interface<PPB_Flash_MessageLoop>())
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return PP_ERROR_NOINTERFACE;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return get_interface<PPB_Flash_MessageLoop>()->Run(pp_resource());
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void MessageLoop::Quit() {
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (has_interface<PPB_Flash_MessageLoop>())
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    get_interface<PPB_Flash_MessageLoop>()->Quit(pp_resource());
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace flash
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace pp
52