Cync
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / ARDroneLib / VP_SDK / VP_Api / vp_api_io_multi_stage.c
1 /**
2  *  \brief    VP Api. Composite Stage Declaration
3  *  \author   Sylvain Gaeremynck <sylvain.gaeremynck@parrot.fr>
4  *  \author   Aurelien Morelle <aurelien.morelle@parrot.fr>
5  *  \author   Thomas Landais <thomas.landais@parrot.fr>
6  *  \version  1.0
7  *  \date     first release 21/03/2007
8  */
9
10 #include <VP_Api/vp_api_io_multi_stage.h>
11 #include <VP_Api/vp_api_error.h>
12 #include <VP_Os/vp_os_assert.h>
13
14 C_RESULT
15 vp_api_multi_stage_open(vp_api_io_multi_stage_config_t *cfg)
16 {
17   uint32_t i;
18
19   for(i = 0; i < cfg->nb_stages; i++)
20   {
21     VP_OS_ASSERT(cfg->stages[i].funcs.open);
22     VP_OS_ASSERT(cfg->stages[i].funcs.transform);
23     VP_OS_ASSERT(cfg->stages[i].funcs.close);
24
25     if(VP_FAILED(cfg->stages[i].funcs.open(cfg->stages[i].cfg)))
26       return (VP_FAILURE);
27   }
28
29   return (VP_SUCCESS);
30 }
31
32 C_RESULT
33 vp_api_multi_stage_transform(vp_api_io_multi_stage_config_t *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
34 {
35   uint32_t i;
36   C_RESULT res = (VP_FAILURE);
37
38   // if a stage is selected then execute only this one
39   if(cfg->activ_stage >= 0 && cfg->activ_stage < (int32_t)cfg->nb_stages)
40     res = cfg->stages[cfg->activ_stage].funcs.transform(cfg->stages[cfg->activ_stage].cfg, in, out);
41
42   // Otherwise if activ_stage == -1 then execute all stages
43   if(cfg->activ_stage == VP_API_EXECUTE_ALL_STAGES)
44   {
45     res = VP_SUCCESS;
46     for(i = 0; i < cfg->nb_stages && res == VP_SUCCESS; i++)
47     {
48       res = cfg->stages[i].funcs.transform(cfg->stages[i].cfg, in, out);
49     }
50   }
51
52   if(cfg->activ_stage == VP_API_EXECUTE_NO_STAGE)
53     res = VP_SUCCESS;
54
55   return res;
56 }
57
58 C_RESULT
59 vp_api_multi_stage_close(vp_api_io_multi_stage_config_t *cfg)
60 {
61   uint32_t i;
62
63   for(i = 0; i < cfg->nb_stages; i++)
64   {
65     if(VP_FAILED(cfg->stages[i].funcs.close(cfg->stages[i].cfg)))
66       return (VP_FAILURE);
67   }
68
69   return (VP_SUCCESS);
70 }