javauis/mmapi_qt/baseline/src/mmafunctionserver.cpp
changeset 26 dc7c549001d5
parent 23 98ccebc37403
equal deleted inserted replaced
23:98ccebc37403 26:dc7c549001d5
    29 #include "cmmaglobalvolume.h"
    29 #include "cmmaglobalvolume.h"
    30 #endif // RD_JAVA_VOLUME_CONTROL
    30 #endif // RD_JAVA_VOLUME_CONTROL
    31 
    31 
    32 MMAFunctionServer::MMAFunctionServer(JNIEnv& aJni, jobject aPeer): java::util::FunctionServer("JavaMMAPIFunctionServer")
    32 MMAFunctionServer::MMAFunctionServer(JNIEnv& aJni, jobject aPeer): java::util::FunctionServer("JavaMMAPIFunctionServer")
    33 {
    33 {
    34 	LOG( EJavaMMAPI, EInfo, "++MMAFunctionServer::MMAFunctionServer");
    34     LOG(EJavaMMAPI, EInfo, "++MMAFunctionServer::MMAFunctionServer");
    35     createServerToNewThread();
    35     createServerToNewThread();
    36     attachToVm(aJni, aPeer);
    36     attachToVm(aJni, aPeer);
    37     mVmAttached = true;
    37     mVmAttached = true;
    38     iServer = reinterpret_cast<java::util::FunctionServer*>(this);
    38     iServer = reinterpret_cast<java::util::FunctionServer*>(this);
    39 }
    39 }
    40 
    40 
    41 MMAFunctionServer::~MMAFunctionServer()
    41 MMAFunctionServer::~MMAFunctionServer()
    42 {
    42 {
    43     LOG( EJavaMMAPI, EInfo, "MMA::MMAFunctionServer::~MMAFunctionServer()");
    43     LOG(EJavaMMAPI, EInfo, "MMA::MMAFunctionServer::~MMAFunctionServer()");
    44         if (mVmAttached)
    44     if (mVmAttached)
    45         {
    45     {
    46             detachFromVm();
    46         detachFromVm();
    47         }
    47     }
    48         stopServer();
    48     stopServer();
    49 #ifdef RD_JAVA_VOLUME_CONTROL
    49 #ifdef RD_JAVA_VOLUME_CONTROL
    50     delete iGlobalVolume;
    50     delete iGlobalVolume;
    51 #endif // RD_JAVA_VOLUME_CONTROL
    51 #endif // RD_JAVA_VOLUME_CONTROL
    52 }
    52 }
    53 
    53 
    54 TInt MMAFunctionServer::NewL(JNIEnv& aJni, jobject aPeer)
    54 TInt MMAFunctionServer::NewL(JNIEnv& aJni, jobject aPeer)
    55 {
    55 {
    56 	
    56 
    57 	MMAFunctionServer* self = 	new(ELeave) MMAFunctionServer(aJni,aPeer);
    57     MMAFunctionServer* self =   new(ELeave) MMAFunctionServer(aJni,aPeer);
    58 	self->ConstructL(aJni,aPeer);
    58     self->ConstructL(aJni,aPeer);
    59 	return reinterpret_cast<TInt>(self);
    59     return reinterpret_cast<TInt>(self);
    60 }
    60 }
    61 void MMAFunctionServer::ConstructL(JNIEnv& aJni,
    61 void MMAFunctionServer::ConstructL(JNIEnv& aJni,
    62                                  jobject aPeer
    62                                    jobject /*aPeer*/
    63                                  )
    63                                   )
    64 {
    64 {
    65     LOG( EJavaMMAPI, EInfo, "MMA::MMAFunctionServer::ConstructL +");
    65     LOG(EJavaMMAPI, EInfo, "MMA::MMAFunctionServer::ConstructL +");
    66     aJni.GetJavaVM(&iJavaVM); // Get pointer to VM
    66     aJni.GetJavaVM(&iJavaVM); // Get pointer to VM
    67     LOG( EJavaMMAPI, EInfo, "MMA::MMAFunctionServer::ConstructL -");
    67     LOG(EJavaMMAPI, EInfo, "MMA::MMAFunctionServer::ConstructL -");
    68 }
    68 }
    69 
    69 
    70 java::util::FunctionServer* MMAFunctionServer::getFunctionServer() const
    70 java::util::FunctionServer* MMAFunctionServer::getFunctionServer() const
    71 {
    71 {
    72 	LOG( EJavaMMAPI, EInfo, "++getFunctionServer1");
    72     LOG(EJavaMMAPI, EInfo, "++getFunctionServer1");
    73     JELOG2(EJavaMMAPI);
    73     JELOG2(EJavaMMAPI);
    74     return iServer;
    74     return iServer;
    75 }
    75 }
    76 JNIEnv* MMAFunctionServer::getValidJniEnv()
    76 JNIEnv* MMAFunctionServer::getValidJniEnv()
    77     {
    77 {
    78         JELOG2(EJavaLocation);
    78     JELOG2(EJavaLocation);
    79         return mJniEnv;
    79     return mJniEnv;
    80     }
    80 }
    81 jobject MMAFunctionServer::getPeer()
    81 jobject MMAFunctionServer::getPeer()
    82     {
    82 {
    83         return mJavaPeerObject;
    83     return mJavaPeerObject;
    84     }
    84 }
    85 
    85 
    86 void MMAFunctionServer::ConstructSvrL()
    86 void MMAFunctionServer::ConstructSvrL()
    87 {
    87 {
    88     // creating fbs session
    88     // creating fbs session
    89     User::LeaveIfError(RFbsSession::Connect());
    89     User::LeaveIfError(RFbsSession::Connect());
    90     iFbsSessionConnected = ETrue;
    90     iFbsSessionConnected = ETrue;
    91     LOG( EJavaMMAPI, EInfo, "MMA::MMAFunctionServer::ConstructSvrL ok");
    91     LOG(EJavaMMAPI, EInfo, "MMA::MMAFunctionServer::ConstructSvrL ok");
    92 }
    92 }
    93 
    93 
    94 EXPORT_C void MMAFunctionServer::StaticAddObjectFromHandleL(
    94 EXPORT_C void MMAFunctionServer::StaticAddObjectFromHandleL(
    95     MMAFunctionServer* aEventSource,
    95     MMAFunctionServer* aEventSource,
    96     TInt aHandle)
    96     TInt aHandle)
   184     iPlayers.ResetAndDestroy();
   184     iPlayers.ResetAndDestroy();
   185 }
   185 }
   186 
   186 
   187 void MMAFunctionServer::AddObjectFromHandleL(TInt aHandle)
   187 void MMAFunctionServer::AddObjectFromHandleL(TInt aHandle)
   188 {
   188 {
   189 	User::LeaveIfError(iObjects.Append(reinterpret_cast< CBase* >(aHandle)));
   189     User::LeaveIfError(iObjects.Append(reinterpret_cast< CBase* >(aHandle)));
   190 }
   190 }
   191 
   191 
   192 
   192 
   193 void MMAFunctionServer::FinalizeSvr()
   193 void MMAFunctionServer::FinalizeSvr()
   194 {
   194 {
   195     LOG1( EJavaMMAPI, EInfo, "MMA::MMAFunctionServer::FinalizeSvr() object count = %d",
   195     LOG1(EJavaMMAPI, EInfo, "MMA::MMAFunctionServer::FinalizeSvr() object count = %d",
   196               iObjects.Count());
   196          iObjects.Count());
   197     LOG1( EJavaMMAPI, EInfo, "MMA::MMAFunctionServer::FinalizeSvr() player count = %d",
   197     LOG1(EJavaMMAPI, EInfo, "MMA::MMAFunctionServer::FinalizeSvr() player count = %d",
   198               iPlayers.Count());
   198          iPlayers.Count());
   199 
   199 
   200     // After object array alements are deleted all external references to
   200     // After object array alements are deleted all external references to
   201     // player objects are removed and player array can be deleted.
   201     // player objects are removed and player array can be deleted.
   202     iObjects.ResetAndDestroy();
   202     iObjects.ResetAndDestroy();
   203     iPlayers.ResetAndDestroy();
   203     iPlayers.ResetAndDestroy();
   205     if (iFbsSessionConnected)
   205     if (iFbsSessionConnected)
   206     {
   206     {
   207         RFbsSession::Disconnect();
   207         RFbsSession::Disconnect();
   208         iFbsSessionConnected = EFalse;
   208         iFbsSessionConnected = EFalse;
   209     }
   209     }
   210     LOG( EJavaMMAPI, EInfo, "MMA::MMAFunctionServer::FinalizeSvr() ok");
   210     LOG(EJavaMMAPI, EInfo, "MMA::MMAFunctionServer::FinalizeSvr() ok");
   211 }
   211 }
   212 
   212 
   213 
   213 
   214 void MMAFunctionServer::PostEvent(CMMAEvent* aEvent, TInt /*aPriority*/)
   214 void MMAFunctionServer::PostEvent(CMMAEvent* aEvent, TInt /*aPriority*/)
   215 {
   215 {
   216    LOG( EJavaMMAPI, EInfo, "MMAFunctionServer::PostEvent");
   216     LOG(EJavaMMAPI, EInfo, "MMAFunctionServer::PostEvent");
   217    aEvent->Dispatch(*mJniEnv);
   217     aEvent->Dispatch(*mJniEnv);
   218 }
   218 }
   219 
   219 
   220 CMMAPlayer* MMAFunctionServer::FindPlayer(TInt aPlayerHandle)
   220 CMMAPlayer* MMAFunctionServer::FindPlayer(TInt aPlayerHandle)
   221 {
   221 {
   222     LOG( EJavaMMAPI, EInfo, "MMAFunctionServer::FindPlayer");
   222     LOG(EJavaMMAPI, EInfo, "MMAFunctionServer::FindPlayer");
   223     CMMAPlayer* player = reinterpret_cast< CMMAPlayer* >(aPlayerHandle);
   223     CMMAPlayer* player = reinterpret_cast< CMMAPlayer* >(aPlayerHandle);
   224     TInt index = iPlayers.Find(player);
   224     TInt index = iPlayers.Find(player);
   225     if (index != KErrNotFound)
   225     if (index != KErrNotFound)
   226     {
   226     {
   227         player = iPlayers[ index ];
   227         player = iPlayers[ index ];
   228         LOG( EJavaMMAPI, EInfo, "MMAFunctionServer::FindPlayer: player found");
   228         LOG(EJavaMMAPI, EInfo, "MMAFunctionServer::FindPlayer: player found");
   229     }
   229     }
   230     else
   230     else
   231     {
   231     {
   232         LOG( EJavaMMAPI, EInfo, "MMAFunctionServer::FindPlayer: player not found");
   232         LOG(EJavaMMAPI, EInfo, "MMAFunctionServer::FindPlayer: player not found");
   233         player = NULL;
   233         player = NULL;
   234     }
   234     }
   235     return player;
   235     return player;
   236 }
   236 }
   237 #ifdef RD_JAVA_VOLUME_CONTROL
   237 #ifdef RD_JAVA_VOLUME_CONTROL