component_template.c 3.3 KB

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