OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PPAPI_CPP_INSTANCE_H_ | 5 #ifndef PPAPI_CPP_INSTANCE_H_ |
6 #define PPAPI_CPP_INSTANCE_H_ | 6 #define PPAPI_CPP_INSTANCE_H_ |
7 | 7 |
8 /// @file | 8 /// @file |
9 /// This file defines the C++ wrapper for an instance. | 9 /// This file defines the C++ wrapper for an instance. |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "ppapi/c/pp_instance.h" | 14 #include "ppapi/c/pp_instance.h" |
15 #include "ppapi/c/pp_resource.h" | 15 #include "ppapi/c/pp_resource.h" |
16 #include "ppapi/c/pp_stdint.h" | 16 #include "ppapi/c/pp_stdint.h" |
| 17 #include "ppapi/cpp/instance_handle.h" |
17 #include "ppapi/cpp/view.h" | 18 #include "ppapi/cpp/view.h" |
18 | 19 |
19 struct PP_InputEvent; | 20 struct PP_InputEvent; |
20 | 21 |
21 /// The C++ interface to the Pepper API. | 22 /// The C++ interface to the Pepper API. |
22 namespace pp { | 23 namespace pp { |
23 | 24 |
24 class Graphics2D; | 25 class Graphics2D; |
25 class Graphics3D; | 26 class Graphics3D; |
26 class InputEvent; | 27 class InputEvent; |
| 28 class InstanceHandle; |
27 class Rect; | 29 class Rect; |
28 class URLLoader; | 30 class URLLoader; |
29 class Var; | 31 class Var; |
30 | 32 |
31 class Instance { | 33 class Instance { |
32 public: | 34 public: |
33 /// Default constructor. Construction of an instance should only be done in | 35 /// Default constructor. Construction of an instance should only be done in |
34 /// response to a browser request in <code>Module::CreateInstance</code>. | 36 /// response to a browser request in <code>Module::CreateInstance</code>. |
35 /// Otherwise, the instance will lack the proper bookkeeping in the browser | 37 /// Otherwise, the instance will lack the proper bookkeeping in the browser |
36 /// and in the C++ wrapper. | 38 /// and in the C++ wrapper. |
(...skipping 16 matching lines...) Expand all Loading... |
53 /// file writes from this destructor since they will be immediately canceled. | 55 /// file writes from this destructor since they will be immediately canceled. |
54 /// | 56 /// |
55 /// <strong>Note:</strong> This function may be skipped in certain | 57 /// <strong>Note:</strong> This function may be skipped in certain |
56 /// call so the instance can perform cleanup-related tasks. Once this function | 58 /// call so the instance can perform cleanup-related tasks. Once this function |
57 /// returns, the <code>PP_Instance</code> handle will be invalid. This means | 59 /// returns, the <code>PP_Instance</code> handle will be invalid. This means |
58 /// that you can't do any asynchronous operations such as network requests or | 60 /// that you can't do any asynchronous operations such as network requests or |
59 /// file writes from this destructor since they will be immediately canceled. | 61 /// file writes from this destructor since they will be immediately canceled. |
60 virtual ~Instance(); | 62 virtual ~Instance(); |
61 | 63 |
62 /// This function returns the <code>PP_Instance</code> identifying this | 64 /// This function returns the <code>PP_Instance</code> identifying this |
63 /// object. When using the PPAPI C++ wrappers this is not normally necessary, | 65 /// object. |
64 /// but is required when using the lower-level C APIs. | |
65 /// | 66 /// |
66 /// @return A <code>PP_Instance</code> identifying this object. | 67 /// @return A <code>PP_Instance</code> identifying this object. |
67 PP_Instance pp_instance() const { return pp_instance_; } | 68 PP_Instance pp_instance() const { return pp_instance_; } |
68 | 69 |
69 /// Init() initializes this instance with the provided arguments. This | 70 /// Init() initializes this instance with the provided arguments. This |
70 /// function will be called immediately after the instance object is | 71 /// function will be called immediately after the instance object is |
71 /// constructed. | 72 /// constructed. |
72 /// | 73 /// |
73 /// @param[in] argc The number of arguments contained in <code>argn</code> | 74 /// @param[in] argc The number of arguments contained in <code>argn</code> |
74 /// and <code>argv</code>. | 75 /// and <code>argv</code>. |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 /// get the C calls in the first place. | 480 /// get the C calls in the first place. |
480 /// | 481 /// |
481 /// Refer to RemovePerInstanceObject() and GetPerInstanceObject() for further | 482 /// Refer to RemovePerInstanceObject() and GetPerInstanceObject() for further |
482 /// information. | 483 /// information. |
483 /// | 484 /// |
484 /// @param[in] interface_name The name of the interface to associate with the | 485 /// @param[in] interface_name The name of the interface to associate with the |
485 /// instance | 486 /// instance |
486 /// @param[in] object | 487 /// @param[in] object |
487 void AddPerInstanceObject(const std::string& interface_name, void* object); | 488 void AddPerInstanceObject(const std::string& interface_name, void* object); |
488 | 489 |
| 490 /// Static version of AddPerInstanceObject that takes an InstanceHandle. As |
| 491 /// with all other instance functions, this must only be called on the main |
| 492 /// thread. |
| 493 static void AddPerInstanceObject(const InstanceHandle& instance, |
| 494 const std::string& interface_name, |
| 495 void* object); |
| 496 |
489 // {PENDING: summarize Remove method here} | 497 // {PENDING: summarize Remove method here} |
490 /// | 498 /// |
491 /// Refer to AddPerInstanceObject() for further information. | 499 /// Refer to AddPerInstanceObject() for further information. |
492 /// | 500 /// |
493 /// @param[in] interface_name The name of the interface to associate with the | 501 /// @param[in] interface_name The name of the interface to associate with the |
494 /// instance | 502 /// instance |
495 /// @param[in] object | 503 /// @param[in] object |
496 void RemovePerInstanceObject(const std::string& interface_name, void* object); | 504 void RemovePerInstanceObject(const std::string& interface_name, void* object); |
497 | 505 |
| 506 /// Static version of AddPerInstanceObject that takes an InstanceHandle. As |
| 507 /// with all other instance functions, this must only be called on the main |
| 508 /// thread. |
| 509 static void RemovePerInstanceObject(const InstanceHandle& instance, |
| 510 const std::string& interface_name, |
| 511 void* object); |
| 512 |
498 /// Look up an object previously associated with an instance. Returns NULL | 513 /// Look up an object previously associated with an instance. Returns NULL |
499 /// if the instance is invalid or there is no object for the given interface | 514 /// if the instance is invalid or there is no object for the given interface |
500 /// name on the instance. | 515 /// name on the instance. |
501 /// | 516 /// |
502 /// Refer to AddPerInstanceObject() for further information. | 517 /// Refer to AddPerInstanceObject() for further information. |
503 /// | 518 /// |
504 /// @param[in] instance | 519 /// @param[in] instance |
505 /// @param[in] interface_name The name of the interface to associate with the | 520 /// @param[in] interface_name The name of the interface to associate with the |
506 /// instance. | 521 /// instance. |
507 static void* GetPerInstanceObject(PP_Instance instance, | 522 static void* GetPerInstanceObject(PP_Instance instance, |
508 const std::string& interface_name); | 523 const std::string& interface_name); |
509 | 524 |
510 private: | 525 private: |
511 PP_Instance pp_instance_; | 526 PP_Instance pp_instance_; |
512 | 527 |
513 typedef std::map<std::string, void*> InterfaceNameToObjectMap; | 528 typedef std::map<std::string, void*> InterfaceNameToObjectMap; |
514 InterfaceNameToObjectMap interface_name_to_objects_; | 529 InterfaceNameToObjectMap interface_name_to_objects_; |
515 }; | 530 }; |
516 | 531 |
517 } // namespace pp | 532 } // namespace pp |
518 | 533 |
519 #endif // PPAPI_CPP_INSTANCE_H_ | 534 #endif // PPAPI_CPP_INSTANCE_H_ |
OLD | NEW |