component_template.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2019, Chips&Media
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include <string.h>
  26. #include "component.h"
  27. typedef struct {
  28. Uint32 dummy;
  29. } ExampleContext;
  30. static CNMComponentParamRet GetParameterExample(ComponentImpl* from, ComponentImpl* my, GetParameterCMD commandType, void* data)
  31. {
  32. BOOL result = TRUE;
  33. PortContainer* container;
  34. switch(commandType) {
  35. case GET_PARAM_COM_IS_CONTAINER_CONUSUMED:
  36. container = (PortContainer*)data;
  37. container->consumed = TRUE;
  38. break;
  39. default:
  40. result = FALSE;
  41. break;
  42. }
  43. if (result == TRUE) return CNM_COMPONENT_PARAM_SUCCESS;
  44. else return CNM_COMPONENT_PARAM_FAILURE;
  45. }
  46. static CNMComponentParamRet SetParameterExample(ComponentImpl* from, ComponentImpl* my, SetParameterCMD commandType, void* data)
  47. {
  48. BOOL result = TRUE;
  49. switch(commandType) {
  50. default:
  51. result = FALSE;
  52. break;
  53. }
  54. if (result == TRUE) return CNM_COMPONENT_PARAM_SUCCESS;
  55. else return CNM_COMPONENT_PARAM_FAILURE;
  56. }
  57. static BOOL PrepareExample(ComponentImpl* com, BOOL* done)
  58. {
  59. *done = TRUE;
  60. return TRUE;
  61. }
  62. static BOOL ExecuteExample(ComponentImpl* com, PortContainer* in, PortContainer* out)
  63. {
  64. return TRUE;
  65. }
  66. static BOOL DestroyExample(ComponentImpl* com)
  67. {
  68. ExampleContext* myParam = (ExampleContext*)com->context;
  69. osal_free(myParam);
  70. return TRUE;
  71. }
  72. static Component CreateExample(ComponentImpl* com, CNMComponentConfig* componentParam)
  73. {
  74. com->context = (ExampleContext*)osal_malloc(sizeof(ExampleContext));
  75. osal_memset(com->context, 0, sizeof(ExampleContext));
  76. return (Component)com;
  77. }
  78. static void ReleaseExample(ComponentImpl* com)
  79. {
  80. }
  81. ComponentImpl exampleComponentImpl = {
  82. "example",
  83. NULL,
  84. {0,},
  85. {0,},
  86. sizeof(PortContainer),
  87. 5,
  88. CreateExample,
  89. GetParameterExample,
  90. SetParameterExample,
  91. PrepareExample,
  92. ExecuteExample,
  93. ReleaseExample,
  94. DestroyExample
  95. };