00001 /* 00002 * Copyright 2008-2010 Arsen Chaloyan 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 * $Id: mrcp_state_machine.h 1474 2010-02-07 20:51:47Z achaloyan $ 00017 */ 00018 00019 #ifndef MRCP_STATE_MACHINE_H 00020 #define MRCP_STATE_MACHINE_H 00021 00022 /** 00023 * @file mrcp_state_machine.h 00024 * @brief MRCP State Machine 00025 */ 00026 00027 #include "mrcp_types.h" 00028 00029 APT_BEGIN_EXTERN_C 00030 00031 /** MRCP state machine declaration */ 00032 typedef struct mrcp_state_machine_t mrcp_state_machine_t; 00033 00034 00035 /** MRCP state machine */ 00036 struct mrcp_state_machine_t { 00037 /** External object associated with state machine */ 00038 void *obj; 00039 /** State either active or deactivating */ 00040 apt_bool_t active; 00041 00042 /** Virtual update */ 00043 apt_bool_t (*update)(mrcp_state_machine_t *state_machine, mrcp_message_t *message); 00044 /** Deactivate */ 00045 apt_bool_t (*deactivate)(mrcp_state_machine_t *state_machine); 00046 00047 00048 /** Message dispatcher */ 00049 apt_bool_t (*on_dispatch)(mrcp_state_machine_t *state_machine, mrcp_message_t *message); 00050 /** Deactivated */ 00051 apt_bool_t (*on_deactivate)(mrcp_state_machine_t *state_machine); 00052 }; 00053 00054 /** Initialize MRCP state machine */ 00055 static APR_INLINE void mrcp_state_machine_init(mrcp_state_machine_t *state_machine, void *obj) 00056 { 00057 state_machine->obj = obj; 00058 state_machine->active = TRUE; 00059 state_machine->on_dispatch = NULL; 00060 state_machine->on_deactivate = NULL; 00061 state_machine->update = NULL; 00062 state_machine->deactivate = NULL; 00063 } 00064 00065 /** Update MRCP state machine */ 00066 static APR_INLINE apt_bool_t mrcp_state_machine_update(mrcp_state_machine_t *state_machine, mrcp_message_t *message) 00067 { 00068 if(state_machine->update) { 00069 return state_machine->update(state_machine,message); 00070 } 00071 return FALSE; 00072 } 00073 00074 /** Deactivate MRCP state machine */ 00075 static APR_INLINE apt_bool_t mrcp_state_machine_deactivate(mrcp_state_machine_t *state_machine) 00076 { 00077 if(state_machine->deactivate) { 00078 state_machine->active = FALSE; 00079 return state_machine->deactivate(state_machine); 00080 } 00081 return FALSE; 00082 } 00083 00084 APT_END_EXTERN_C 00085 00086 #endif /* MRCP_STATE_MACHINE_H */