javacommons/javastorage/src/server/main.cpp
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:  StorageServer Main
       
    15 *
       
    16 */
       
    17 
       
    18 #include <cstdio>
       
    19 #include <signal.h>
       
    20 #include <memory.h>
       
    21 #include <string>
       
    22 #include <sys/types.h>
       
    23 #include <string.h>
       
    24 #include <unistd.h>
       
    25 
       
    26 #include "monitor.h"
       
    27 #include "storageserver.h"
       
    28 
       
    29 using namespace java::storage;
       
    30 
       
    31 StorageServer*          server = 0;
       
    32 java::util::Monitor*    monitor = 0;
       
    33 
       
    34 void sigint_handler(int /*sig*/)
       
    35 {
       
    36     monitor->notify();
       
    37 }
       
    38 
       
    39 int main(int /*ac*/, char** /*av*/)
       
    40 {
       
    41     struct sigaction sa;
       
    42     memset(&sa, 0, sizeof(sa));
       
    43     sa.sa_handler = sigint_handler;
       
    44     sigaction(SIGINT, &sa, NULL);
       
    45 
       
    46     std::puts("StorageServer started.");
       
    47 
       
    48     monitor = java::util::Monitor::createMonitor();
       
    49     server = new StorageServer(monitor);
       
    50     server->start();
       
    51     monitor->wait();
       
    52 
       
    53     if (server)
       
    54     {
       
    55         delete server;
       
    56         server = NULL;
       
    57     }
       
    58     if (monitor)
       
    59     {
       
    60         delete monitor;
       
    61         monitor = NULL;
       
    62     }
       
    63 
       
    64     std::puts("StorageServer stopped.");
       
    65     return 0;
       
    66 }