Exemple #1
0
/*------------------------------------------------------------------------------------------------------------------ 
-- FUNCTION: startClient 
-- 
-- DATE: January 18, 2014 
-- 
-- REVISIONS:  
-- 
-- DESIGNER: Robin Hsieh 
-- 
-- PROGRAMMER: Robin Hsieh 
-- 
-- INTERFACE: void startClient(char* inputfname, int priority)
--              char* inputfname:    The char array of the inputfilename from user.
--              int priority:        The int of priority from user.
-- 
-- RETURNS: Void
-- 
-- NOTES:
-- This function is to start the client program to receive a txt file from the server.
--
------------------------------------------------------------------------------------------------------------------*/
void startClient(char* inputfname, int priority)
{

    int msq_id;
    pid_t pid = getpid();

    pthread_t clientThreadId;

    printf("Client started\n");

    msq_id = OpenMessageQueue();

    Mesg *msg = (Mesg*) malloc(sizeof(Mesg));
    msg->mesg_type = 1;
    sprintf(msg->mesg_data, "%s %d %d", inputfname, pid, priority);
    msg->mesg_len = strlen(msg->mesg_data);
    msg->fileTransferCompleted = 0;
    msg->pid = pid;

    if ((send_message(msq_id, msg)) == -1)
    {
        fprintf(stderr, "client: send_message error\n");
        exit(1);
    }

    pthread_create(&clientThreadId, NULL, client_thread, (void *)&msq_id);
    pthread_join(clientThreadId, NULL);

    free(msg);
}
Exemple #2
0
int gws_command_str(P_GWS_KPI pKpiLcd,int nKpiLcdId,int action, char* parameter) {
    int nQid = -1;
    if (NULL == parameter) return -1;
    if ((nQid = OpenMessageQueue(0)) >= 0) {
        int para = atoi(parameter);

        lcd_cache.m_timer = time(&lcd_cache.m_timer);
        switch (action) {
            case SET_MODE:  lcd_cache.m_nMode = para;       break;
            case SET_CHAN:  lcd_cache.m_nChannel = para;    break;
            case SET_TXPWR: lcd_cache.m_nTxPower = para;    break;
            case SET_TXON:  break;
            case SCAN_CHAN:
                if (pKpiLcd != NULL && !svrIsScanning()) {
                    lcd_cache.m_nScanStartChan = iw_getcurrchan(pKpiLcd,nKpiLcdId,nKpiLcdId);
                } else return -4;
                break;
            default: return -2;
        }
        CommandGo(action, parameter, nQid, false);
    } else {
        printf("\nError can not open message queue\n");
        return -3;
    }
    return 0;
}
Exemple #3
0
bool svrInitCommandHandler(SerialCom* comm,PipeShell* shell,char* sIfName,bool dbg_gws) {
    struct itimerval interval;

    ShowStatusBar("%s", "Handler Init....\n");
    if (NULL == comm || NULL == shell || NULL == sIfName) return false;
    static_chp.m_comm = comm;
    static_chp.m_shell = shell;
    static_chp.m_ifName = sIfName;
    static_chp.m_nQid = OpenMessageQueue(1);
    static_chp.m_pKpi = CreateShm(&static_chp.m_nIdentifier);

    ShowStatusBar("%s", "MSQ & SHM OK\n");
    if (static_chp.m_nQid < 0 || NULL == static_chp.m_pKpi) {
        if (static_chp.m_nQid < 0) {
            ShowStatusBar("Error on create message queue,error=%d", errno);
            svrSetErrorNo(errno);
            return false;
        } else if (NULL == static_chp.m_pKpi) {
            ShowStatusBar("Error on open share memory,error=%d", errno);
            svrSetErrorNo(errno);
            return false;
        }
    }
    ShowStatusBar("%s", "Turnning on GWS Tx....\n");
    ScSend(static_chp.m_comm, "txon\n", 5);
    ShowStatusBar("%s", "Adjusting GWS channel....\n");
    iw_setchannel(-1,static_chp.m_pKpi,static_chp.m_nIdentifier);

    pthread_mutex_init(&mutex_lock_timer,NULL);
    interval.it_value.tv_sec = 0;
    interval.it_value.tv_usec = TIME_SLOT;
    interval.it_interval.tv_sec = 0;
    interval.it_interval.tv_usec = TIME_SLOT;
    static_debug_gws = dbg_gws;
    signal(SIGALRM, svrTimer);
    setitimer(ITIMER_REAL, &interval, NULL);
    ShowStatusBar("%s", "Initialize Handler OK!");
    return true;
}