javamanager/javacaptain/src/main.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 11 May 2010 16:07:20 +0300
branchRCL_3
changeset 24 0fd27995241b
parent 19 04becd199f91
child 25 9ac0a0a7da70
permissions -rw-r--r--
Revision: v2.1.24 Kit: 201019

/*
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  JavaCaptain Main
*
*/

#ifndef __SYMBIAN32__
#include <signal.h>
#include <pthread.h>
#include "signalhandler.h"
#endif /* __SYMBIAN32__ */

#include <cstdio>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#include "logger.h"
#include "monitor.h"

#include "core.h"

using namespace java::captain;
using namespace java::util;

Monitor* monitor = NULL;

#ifdef RD_JAVA_S60_RELEASE_9_2_ONWARDS
#include <dirent.h>
void makeHomeDir()
{
    // open(filename) fails if c:\private\<uid> does not exist in 9.2
    // This used to work in 5.0
    char* homeDir = "c:\\private\\200211DC";
    DIR* dir = opendir(homeDir);
    if (dir != NULL)
    {
        closedir(dir);
    }
    else
    {
        int rc = mkdir(homeDir, S_IRWXU);
        if (rc < 0)
        {
            WLOG2(EJavaCaptain, "creating %s failed, rc = %d", homeDir, rc);
        }
    }
}
#endif

int main(int ac, char** av)
{
    JELOG2(EJavaCaptain);

#ifdef RD_JAVA_S60_RELEASE_9_2_ONWARDS
    makeHomeDir();
#endif

    // check if started by IAD installation
    if (ac == 2 && strcmp(av[1], "iad") == 0)
    {
        LOG(EJavaCaptain, EInfo, "creating iad boot event flag");
        int fd = open("iadboot.dat", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
        if (fd < 0)
        {
            ELOG1(EJavaCaptain, "create boot event flag failed: %s", strerror(errno));
        }
        else
        {
            close(fd);
        }
    }

#ifndef __SYMBIAN32__
    sigset_t old, block;
    sigemptyset(&old);
    sigfillset(&block);

    if (!pthread_sigmask(SIG_BLOCK, &block, &old))
    {
        SignalHandler sh;
        std::puts("JavaCaptain Press Ctrl-C to exit");
#endif /* __SYMBIAN32__ */

        monitor = Monitor::createMonitor();
        Core* core = new Core(monitor);
        core->start();

#ifndef __SYMBIAN32__
        sh.start();
#endif /* __SYMBIAN32__ */

        monitor->wait();
        core->stop();

        delete core;
        delete monitor;

#ifndef __SYMBIAN32__
        sh.stop();
        pthread_sigmask(SIG_SETMASK, &old, NULL);
    }
#endif /* __SYMBIAN32__ */

    return 0;
}