1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 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 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 #ifndef PV_INTERFACE_CMD_MESSAGE_H_INCLUDED 19 #define PV_INTERFACE_CMD_MESSAGE_H_INCLUDED 20 21 #ifndef PV_COMMON_TYPES_H_INCLUDED 22 #include "pv_common_types.h" 23 #endif 24 25 #ifndef PV_ENGINE_TYPES_H_INCLUDED 26 #include "pv_engine_types.h" 27 #endif 28 29 /** 30 * CPVInterfaceCmdMessage Class 31 * 32 * CPVInterfaceCmdMessage is the interface to the pv2way SDK, which 33 * allows initialization, control, and termination of a two-way terminal. 34 * The application is expected to contain and maintain a pointer to the 35 * CPV2WayInterface instance at all times that a call is active. 36 * The CPV2WayFactory factory class is to be used to create and 37 * delete instances of this class 38 **/ 39 class CPVCmnInterfaceCmdMessage 40 { 41 public: CPVCmnInterfaceCmdMessage(int aType,OsclAny * aContextData)42 CPVCmnInterfaceCmdMessage(int aType, 43 OsclAny* aContextData) : iId(0), 44 iType(aType), 45 iPriority(0), 46 iContextData(aContextData) {}; 47 CPVCmnInterfaceCmdMessage()48 CPVCmnInterfaceCmdMessage() {}; 49 ~CPVCmnInterfaceCmdMessage()50 virtual ~CPVCmnInterfaceCmdMessage() {}; 51 GetCommandId()52 PVCommandId GetCommandId() 53 { 54 return iId; 55 } GetType()56 int GetType() 57 { 58 return iType; 59 } GetContextData()60 OsclAny *GetContextData() 61 { 62 return iContextData; 63 } 64 65 /** 66 * The algorithm used in OsclPriorityQueue needs a compare function 67 * that returns true when A's priority is less than B's 68 * @return true if A's priority is less than B's, else false 69 */ compare(CPVCmnInterfaceCmdMessage * a,CPVCmnInterfaceCmdMessage * b)70 int compare(CPVCmnInterfaceCmdMessage* a, CPVCmnInterfaceCmdMessage* b) const 71 { 72 if (a->GetPriority() < b->GetPriority()) 73 return 1; 74 else //if no priority, use fifo order. 75 return (a->GetCommandId() > b->GetCommandId()); 76 } 77 GetPriority()78 int32 GetPriority()const 79 { 80 return iPriority; 81 } 82 83 friend int32 operator<(const CPVCmnInterfaceCmdMessage& a, const CPVCmnInterfaceCmdMessage& b); 84 SetId(PVCommandId aId)85 void SetId(PVCommandId aId) 86 { 87 iId = aId; 88 } 89 90 protected: 91 PVCommandId iId; 92 int iType; 93 int32 iPriority; 94 OsclAny* iContextData; 95 96 friend class PVInterfaceProxy; 97 }; 98 99 inline int32 operator<(const CPVCmnInterfaceCmdMessage& a, const CPVCmnInterfaceCmdMessage& b) 100 { 101 //Use priority 102 if (a.iPriority < b.iPriority) 103 { 104 return true; 105 } 106 //If priority is the same, use id. 107 else if (a.iPriority == b.iPriority) 108 { 109 //Smaller id means an older message so process older message first. 110 return (a.iId > b.iId); 111 } 112 else 113 { 114 return false; 115 } 116 } 117 #endif 118 119 120