javacommons/utils/functionserver/inc/functionserver.h
branchRCL_3
changeset 14 04becd199f91
child 18 9ac0a0a7da70
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef FUNCTIONSERVER_H
       
    20 #define FUNCTIONSERVER_H
       
    21 
       
    22 #include <jni.h>
       
    23 #include <memory>
       
    24 #include "javaosheaders.h"
       
    25 #include "os_functionclient.h"
       
    26 #include "os_functionserver.h"
       
    27 #include "exceptionbase.h"
       
    28 #include "logger.h"
       
    29 #include "scopedlocks.h"
       
    30 
       
    31 class MethodCaller;
       
    32 
       
    33 namespace java
       
    34 {
       
    35 namespace util
       
    36 {
       
    37 
       
    38 class Monitor;
       
    39 class OsFunctionServer;
       
    40 class OsFunctionClient;
       
    41 
       
    42 /**
       
    43  * This class provides functionality to execute Symbian's active objects from platform
       
    44  * agnostic code. This based on client/server architecture.
       
    45  * See usage example from \javaextensions\jsr\midp\push\pushregistryplugin\src.s60
       
    46  * directory.
       
    47  */
       
    48 class OS_IMPORT FunctionServer
       
    49 {
       
    50 
       
    51 public:
       
    52     //Constructor(s) & destructor
       
    53     OS_IMPORT virtual ~FunctionServer();
       
    54 
       
    55     OS_IMPORT FunctionServer(const std::string& serverName);
       
    56     OS_IMPORT void createServerToNewThread();
       
    57     OS_IMPORT void createServerToCurrentThread();
       
    58     OS_IMPORT void stopServer();
       
    59 
       
    60     OS_IMPORT void stopServerInsideServerThread(bool aDeleteThisObj);
       
    61     OS_IMPORT void attachToVm(JNIEnv& env, jobject peer);
       
    62     OS_IMPORT void detachFromVm();
       
    63 
       
    64 protected:
       
    65     OS_IMPORT virtual void vmAttached();
       
    66     OS_IMPORT virtual void vmDetached();
       
    67     OS_IMPORT virtual void doServerSideInit();
       
    68     OS_IMPORT virtual void doServerSideClean();
       
    69     OS_IMPORT virtual void startServer();
       
    70 
       
    71 protected:
       
    72     JNIEnv*         mJniEnv;
       
    73     jobject         mJavaPeerObject;
       
    74     jclass          mJavaPeerClass;
       
    75     std::string     mServerName;
       
    76 
       
    77 
       
    78 private: //Methods
       
    79     friend class ::MethodCaller;
       
    80     friend class ServerShutdown;
       
    81 
       
    82     /**
       
    83      * Executes a wrapped function in the UI's thread
       
    84      */
       
    85     int executeInServerThread(const Functor& functor);
       
    86     static void* serverThreadEntryPoint(void* ptr);
       
    87 
       
    88     int doDetachFromVm();
       
    89 
       
    90     int doAttachToVm(JavaVM* javaVm, jobject peer);
       
    91 
       
    92     FunctionServer();
       
    93     FunctionServer(const FunctionServer&);              //No copy constructor allowed
       
    94     FunctionServer& operator= (const FunctionServer&);  //No Assignment operator allowed
       
    95 
       
    96 private: //Members
       
    97 
       
    98     OsFunctionClient        mClient;
       
    99     std::auto_ptr<Monitor>  mMonitor;
       
   100     ScopedMutex             mMutex;
       
   101     // Pointer to the Java VM used to attach the native UI thread to the VM.
       
   102     JavaVM*                 mJavaVm;
       
   103     bool                    mConnectedToClient;
       
   104     OsFunctionServer*       mOsServer;
       
   105     bool                    mServerTerminating;
       
   106     bool                    mServerRunningInSameThread;
       
   107     bool                    mDeleteThisObj;
       
   108 
       
   109     //Internal operations.
       
   110     void init();
       
   111     void createAndStartSrv();
       
   112 
       
   113 };
       
   114 
       
   115 } //end namespace util
       
   116 } //end namespace java
       
   117 #endif // FUNCTIONSERVER_H
       
   118