lightduer_dcs_router.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * Copyright (2017) Baidu Inc. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * File: lightduer_dcs_router.h
  18. * Auth: Gang Chen (chengang12@baidu.com)
  19. * Desc: Light duer DCS APIS.
  20. */
  21. #ifndef BAIDU_DUER_LIGHTDUER_DCS_ROUTER_H
  22. #define BAIDU_DUER_LIGHTDUER_DCS_ROUTER_H
  23. #include <stdlib.h>
  24. #include "baidu_json.h"
  25. #include "lightduer_types.h"
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /**
  30. * DCS directive handler. The handler will be implemented by developer.
  31. *
  32. * @PARAM[in] directive: the directive info, include directive name, handler, etc.
  33. *
  34. * @return: return code must be one of following values:
  35. * // no error.
  36. * DUER_OK = 0,
  37. * // directive format incorrect, such missing token in Play directive.
  38. * DUER_MSG_RSP_BAD_REQUEST = 128,
  39. * // device doesn't support this directive,
  40. * DUER_MSG_RSP_NOT_FOUND = 132, // 4.04
  41. * // all other errors.
  42. * DUER_ERR_FAILED = -0x0001,
  43. * // directive parameter value invalid.
  44. * DUER_ERR_INVALID_PARAMETER = -0x0010,
  45. * // memory overflow.
  46. * DUER_ERR_MEMORY_OVERLOW = -0x0011,
  47. */
  48. typedef duer_status_t (*dcs_directive_handler)(const baidu_json *directive);
  49. typedef baidu_json* (*dcs_client_context_handler)();
  50. typedef struct {
  51. const char *directive_name;
  52. dcs_directive_handler cb;
  53. } duer_directive_list;
  54. /**
  55. * Add dcs directive.
  56. *
  57. * @param directive: the directive info, include directive name, handler, etc.
  58. * @param count, how many directives will be added.
  59. * @param name_space: the namespace of the directives needed to add
  60. * @return 0 if success, negative if failed.
  61. */
  62. duer_status_t duer_add_dcs_directive(const duer_directive_list *directive,
  63. size_t count,
  64. const char *name_space);
  65. /**
  66. * Register callback to get client context.
  67. * Sometimes dcs need to know the device's state.
  68. * Hence, some callbacks are needed to get client context.
  69. *
  70. * @param cb: the callback to get client context.
  71. * @return 0 if success, negative if failed.
  72. */
  73. duer_status_t duer_reg_client_context_cb(dcs_client_context_handler cb);
  74. /**
  75. * DESC:
  76. * Used to create dcs event.
  77. *
  78. * @PARAM[in] namespace: the namespace of the event need to report.
  79. * @PARAM[in] name: the name the event need to report.
  80. * @PARAM[in] need_msg_id: including messageId item or not.
  81. * @RETURN: pinter of the created dcs event if success, or NULL if failed.
  82. */
  83. baidu_json *duer_create_dcs_event(const char *name_space, const char *name, duer_bool need_msg_id);
  84. /**
  85. * DESC:
  86. * Used to cancel a dcs dialog: the response of a dialogue will be ignored
  87. * if user calling this API before receiving the response.
  88. *
  89. * @PARAM[in] none.
  90. * @RETURN: none.
  91. */
  92. void duer_dcs_dialog_cancel(void);
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif/*BAIDU_DUER_LIGHTDUER_DCS_ROUTER_H*/