acjs.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2015 Autodesk, Inc. All rights reserved.
  4. //
  5. // Use of this software is subject to the terms of the Autodesk license
  6. // agreement provided at the time of installation or download, or which
  7. // otherwise accompanies this software in either electronic or hard copy form.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. // DESCRIPTION: Header for access to AutoCAD JavaScript-specific services.
  12. //
  13. #ifndef _ACJS_H
  14. #define _ACJS_H
  15. #ifdef _ACJSCORESTUB
  16. #define ACJSCORESTUB_PORT __declspec(dllexport)
  17. #else
  18. #define ACJSCORESTUB_PORT __declspec(dllimport)
  19. #endif
  20. typedef char* (*AcJsFunctionPtr) (const char*);
  21. // Mask flags for metadata for native callback function
  22. #define ACJS_FUNC_INVOKEINDOC 0x00000001 // the function needs to be invoked in a document
  23. #define ACJS_FUNC_HANDLE_NULLDOC 0x00000002 // the callback should not assert if the current doc is null, used for commands.
  24. #define ACJSCORESTUB_DEFUN "acjsDefun"
  25. typedef Acad::ErrorStatus (*ACJSCORESTUB_DEFUN_PROC)(const TCHAR* name, AcJsFunctionPtr funcAddr, Adesk::Int32 funcFlags);
  26. /// <summary>
  27. /// Registers a native callback that can be invoked from JavaScript using
  28. /// the built-in exec() function.
  29. /// </summary>
  30. /// <param name="name">
  31. /// Name of the callback.
  32. /// </param>
  33. /// <param name="funcAddr">
  34. /// Function to invoke when callback is invoked.
  35. /// </param>
  36. /// <param name="funcFlags">
  37. /// flags for metadata for native callback function.
  38. /// The flags is set to 0 by default. It can be set to ACJS_FUNC_INVOKEINDOC and can logically ORd with other new flags in future.
  39. /// </param>
  40. /// <returns>
  41. /// Returns Acad::eOk if successful.
  42. /// </returns>
  43. extern "C" ACJSCORESTUB_PORT Acad::ErrorStatus acjsDefun (const TCHAR* name, AcJsFunctionPtr funcAddr, Adesk::Int32 funcFlags = 0);
  44. /// <summary>
  45. /// Invokes a JavaScript callback asyncronously in all browser windows. Useful for firing events.
  46. /// </summary>
  47. /// <param name="name">
  48. /// Name of the callback.
  49. /// </param>
  50. /// <param name="jsonArgs">
  51. /// Arguments formatted as JSON string. Can be NULL if the JavaScript callback
  52. /// doesn't take any arguments.
  53. /// </param>
  54. /// <returns>
  55. /// Returns Acad::eOk if successful.
  56. /// </returns>
  57. /// <remarks>
  58. /// If the callback hasn't been registered in JavaScript, then the operation
  59. /// will be quietly ignored.
  60. /// </remarks>
  61. extern "C" ACJSCORESTUB_PORT Acad::ErrorStatus acjsInvokeAsync (const TCHAR* name,
  62. const TCHAR* jsonArgs);
  63. extern "C" ACJSCORESTUB_PORT Acad::ErrorStatus acjsInvokeAsyncA (const char* name,
  64. const char* jsonArgs);
  65. #endif // _ACJS_H