Exemplo n.º 1
0
shpinfo *get_shp_from_hash(char *filename) {
    shpinfo *result;
    if (!shp_hash) {  // no table to search
        init_shp_hash(1); // so create one
        return NULL;
    }

    //fprintf(stderr,"   searching for %s...",filename);

    result=hashtable_search(shp_hash,filename);

    //    if (result) {
    //        fprintf(stderr,"      found it\n");
    //    } else {
    //        fprintf(stderr,"      it is not there\n");
    //    }

    // If there is one, we have now accessed it, so bump the last access time
    if (result) {
        result->last_access = sec_now();
    }

    return (result);

}
Exemplo n.º 2
0
void popup_time_out_check(int curr_sec) {
    int i;

    // Check only every two minutes or so
    if (popup_time_out_check_last + 120 < curr_sec) {
        popup_time_out_check_last = curr_sec;

        for (i=0;i<MAX_POPUPS;i++) {
            if (pw[i].popup_message_dialog!=NULL) {
                if ((sec_now()-pw[i].sec_opened)>MAX_POPUPS_TIME) {
                    XtPopdown(pw[i].popup_message_dialog);

begin_critical_section(&popup_message_dialog_lock, "popup_gui.c:popup_time_out_check" );

                    XtDestroyWidget(pw[i].popup_message_dialog);
                    pw[i].popup_message_dialog = (Widget)NULL;
                    pw[i].popup_message_data = (Widget)NULL;

end_critical_section(&popup_message_dialog_lock, "popup_gui.c:popup_time_out_check" );

                }

            }
        }
    }
}
Exemplo n.º 3
0
void init_shp_hash(int clobber) {
    //fprintf(stderr," Initializing shape hash \n");
    // make sure we don't leak
    if (shp_hash) {
        if (clobber) {
            hashtable_destroy(shp_hash, 1);
            shp_hash=create_hashtable(SHP_HASH_SIZE,
                                      shape_hash_from_key,
                                      shape_keys_equal);
        }
    } else {
        shp_hash=create_hashtable(SHP_HASH_SIZE,
                                  shape_hash_from_key,
                                  shape_keys_equal);
    }

    // Now set the static timer value to the next time we need to run the purge
    // routine
    purge_time = sec_now() + PURGE_PERIOD;
}
Exemplo n.º 4
0
void add_shp_to_hash(char *filename, SHPHandle sHP) {

    // This function does NOT check whether there already is something in 
    // the hashtable that matches.
    // Check that before calling this routine.

    shpinfo *temp;
    int filenm_len;

    filenm_len=strlen(filename);
    if (!shp_hash) {  // no table to add to
        init_shp_hash(1); // so create one
    }
    temp = (shpinfo *)malloc(sizeof(shpinfo));
    CHECKMALLOC(temp);
    // leave room for terminator
    temp->filename = (char *) malloc(sizeof(char)*(filenm_len+1));
    CHECKMALLOC(temp->filename);

    strncpy(temp->filename,filename,filenm_len+1);
    temp->filename[filenm_len]='\0';  // just to be safe
//    xastir_snprintf(temp->filename,sizeof(shpinfo),"%s",filename);

    temp->root = Xastir_RTreeNewIndex();  
    temp->creation = sec_now();
    temp->last_access = temp->creation;

    build_rtree(&(temp->root),sHP);

    //fprintf(stderr, "  adding %s...",temp->filename);
    if (!hashtable_insert(shp_hash,temp->filename,temp)) {
        fprintf(stderr,"Insert failed on shapefile hash --- fatal\n");
        free(temp->filename);
        free(temp);
        exit(1);
    }
}
Exemplo n.º 5
0
void check_delayed_transmit_queue(int curr_sec) {
    delayed_ack_record_p ptr = delayed_ack_list_head;
    int active_records = 0;


    // Skip this function if we did it during this second already.
    if (delayed_transmit_last_check == curr_sec) {
        return;
    }
    delayed_transmit_last_check = curr_sec;

//fprintf(stderr, "Checking delayed TX queue for something to transmit.\n");
//fprintf(stderr, ".");

    // Run down the linked list checking every record.
    while (ptr != NULL) {
        if (ptr->active_time != 0) {   // Active record
            char new_path[MAX_LINE_SIZE+1];


//fprintf(stderr, "Found active record\n");

            active_records++;


            // Check for a custom path having been set in the Send
            // Message dialog.  If so, use this for our outgoing
            // path instead and reset all of the queued message
            // paths to this station to this new path.
            //
            get_send_message_path(ptr->to_call_sign,
                new_path,
                sizeof(new_path));

            if (new_path[0] != '\0'
                    && strcmp(new_path, ptr->path) != 0) {

                // We have a custom path set which is different than
                // the path saved with the outgoing message.  Change
                // the path to match the new path.
                //
//fprintf(stderr,
//    "Changing queued ack's to new path: %s\n",
//    new_path);

                xastir_snprintf(ptr->path,
                    sizeof(ptr->path),
                    "%s",
                    new_path);
            }


            if (ptr->active_time <= sec_now()) {
                // Transmit it
//fprintf(stderr,"Found something delayed to transmit!  %ld\n",sec_now());

                if (ptr->path[0] == '\0') {
                    transmit_message_data(ptr->to_call_sign,
                        ptr->message_line,
                        NULL);
                }
                else {
                    transmit_message_data(ptr->to_call_sign,
                        ptr->message_line,
                        ptr->path);
                }
                
                ptr->active_time = (time_t)0;
            }
        }
        ptr = ptr->next;
    } 

    // Check if entire list contains inactive records.  If so,
    // delete the list.
    //
    if (!active_records && (delayed_ack_list_head != NULL)) {
        // No active records, but the list isn't empty.  Reclaim the
        // records in the list.
        while (delayed_ack_list_head != NULL) {
            ptr = delayed_ack_list_head->next;
            free(delayed_ack_list_head);
//fprintf(stderr,"Free'ing delayed_ack record\n");
            delayed_ack_list_head = ptr;
        }
    }
}
Exemplo n.º 6
0
int SayText(char *text) {
    OSErr err;
    pid_t child_pid;


    //if (debug_level & 2)
    //fprintf(stderr,"SayText: %s\n",text);

    // Check whether the last text was the same and it hasn't been
    // enough time between them (30 seconds).
    if ( (strcmp(last_speech_text,text) == 0) // Strings match
            && (last_speech_time + 30 > sec_now()) ) {

    //fprintf(stderr,"Same text, skipping speech: %d seconds, %s\n",
    //    (int)(sec_now() - last_speech_time),
    //    text);

        return(1);
    }

    //fprintf(stderr,"Speaking: %s\n",text);

    xastir_snprintf(last_speech_text,
        sizeof(last_speech_text),
        "%s",
        text);
    last_speech_time = sec_now();

    // Check for the variable going out-of-bounds
    if (macspeech_processes < 0) {
        macspeech_processes = 0;
    }

    // Allow only so many processes to be queued up ready to send
    // text to the speech subsystem.
    //
    if (macspeech_processes > 10) { // Too many processes queued up!
        return(1);  // Don't send this string, return to calling program
    }

    // Create a separate process to handle the speech so that our
    // main process can continue processing packets and displaying
    // maps.
    //
    child_pid = fork();

    if (child_pid == -1) {  // The fork failed
        return(1);
    }

    if (child_pid == 0) {   // Child process

        macspeech_processes++;


        // Go back to default signal handler instead of calling
        // restart() on SIGHUP
        (void) signal(SIGHUP,SIG_DFL);


        // Wait for the speech system to be freed up.  Note that if
        // we have multiple processes queued up we don't know in
        // which order they'll get access to the speech subsystem.
        //
        while (SpeechBusy() == true) {
            usleep(1000000);
        }

        // The speech system is free, so send it our text.  Right
        // now we ignore any errors.
        //
        err = SpeakText(channel, text, strlen(text));

        macspeech_processes--;

        // Exit this child process.  We don't need it anymore.
        exit(0);
    }

    else {                  // Parent process
        // Drop through to the return
    }

    return(0);  // Return to the calling program
}
Exemplo n.º 7
0
// Routine which pops up a large message for a few seconds in the
// middle of the screen, then removes it.
//
void popup_ID_message(char *banner, char *message) {
    float my_rotation = 0.0;
    int x = (int)(screen_width/10);
    int y = (int)(screen_height/2);

    if (ATV_screen_ID) {

        // Fill the pixmap with grey so that the black ID text will
        // be seen.
        (void)XSetForeground(XtDisplay(da),gc,MY_BG_COLOR); // Not a mistake!
        (void)XSetBackground(XtDisplay(da),gc,MY_BG_COLOR);
        (void)XFillRectangle(XtDisplay(appshell),
            pixmap_alerts,
            gc,
            0,
            0,
            (unsigned int)screen_width,
            (unsigned int)screen_height);

        /* load font */
        if(!id_font) {
            id_font=(XFontStruct *)XLoadQueryFont (XtDisplay(da), rotated_label_fontname[FONT_ATV_ID]);
 
            if (id_font == NULL) {    // Couldn't get the font!!!
                fprintf(stderr,"popup_ID_message: Couldn't get ATV ID font %s\n",
                    rotated_label_fontname[FONT_ATV_ID]);
                pending_ID_message = 0;
                return;
            }
        }
 
        (void)XSetForeground (XtDisplay(da), gc, colors[0x08]);

        //fprintf(stderr,"%0.1f\t%s\n",my_rotation,label_text);

        if (       ( (my_rotation < -90.0) && (my_rotation > -270.0) )
                || ( (my_rotation >  90.0) && (my_rotation <  270.0) ) ) {
            my_rotation = my_rotation + 180.0;
            (void)XRotDrawAlignedString(XtDisplay(da),
                id_font,
                my_rotation,
                pixmap_alerts,
                gc,
                x,
                y,
                message,
                BRIGHT);
        }
        else {
            (void)XRotDrawAlignedString(XtDisplay(da),
                id_font,
                my_rotation,
                pixmap_alerts,
                gc,
                x,
                y,
                message,
                BLEFT);
        }

        // Schedule a screen update in roughly 3 seconds
        remove_ID_message_time = sec_now() + 3;
        pending_ID_message = 1;

        // Write it to the screen.  Symbols/tracks will disappear during
        // this short interval time.
        (void)XCopyArea(XtDisplay(da),
            pixmap_alerts,
            XtWindow(da),
            gc,
            0,
            0,
            (unsigned int)screen_width,
            (unsigned int)screen_height,
            0,
            0);
    }
    else {  // ATV Screen ID is not enabled
        pending_ID_message = 0;
    }
}
Exemplo n.º 8
0
void popup_message_always(char *banner, char *message) {
    XmString msg_str;
    int j,i;
    Atom delw;


    if (disable_all_popups)
        return;

    if (banner == NULL || message == NULL)
        return;

    i=0;
    for (j=0; j<MAX_POPUPS; j++) {
        if (!pw[j].popup_message_dialog) {
            i=j;
            j=MAX_POPUPS+1;
        }
    }

    if(!pw[i].popup_message_dialog) {
        if (banner!=NULL && message!=NULL) {

begin_critical_section(&popup_message_dialog_lock, "popup_gui.c:popup_message" );

            pw[i].popup_message_dialog = XtVaCreatePopupShell(banner,
                xmDialogShellWidgetClass, appshell,
                XmNdeleteResponse, XmDESTROY,
                XmNdefaultPosition, FALSE,
                XmNtitleString,banner,
// An half-hearted attempt at fixing the problem where a popup
// comes up extremely small.  Setting a minimum size for the popup.
XmNminWidth, 220,
XmNminHeight, 80,
                XmNfontList, fontlist1,
                NULL);

            pw[i].pane = XtVaCreateWidget("popup_message pane",xmPanedWindowWidgetClass, pw[i].popup_message_dialog,
                          XmNbackground, colors[0xff],
                          NULL);

            pw[i].form =  XtVaCreateWidget("popup_message form",xmFormWidgetClass, pw[i].pane,
                            XmNfractionBase, 5,
                            XmNbackground, colors[0xff],
                            XmNautoUnmanage, FALSE,
                            XmNshadowThickness, 1,
                            NULL);

            pw[i].popup_message_data = XtVaCreateManagedWidget("popup_message message",xmLabelWidgetClass, pw[i].form,
                                      XmNtopAttachment, XmATTACH_FORM,
                                      XmNtopOffset, 10,
                                      XmNbottomAttachment, XmATTACH_NONE,
                                      XmNleftAttachment, XmATTACH_FORM,
                                      XmNleftOffset, 10,
                                      XmNrightAttachment, XmATTACH_FORM,
                                      XmNrightOffset, 10,
                                      XmNbackground, colors[0xff],
                                      XmNfontList, fontlist1,
                                      NULL);

            pw[i].button_close = XtVaCreateManagedWidget(langcode("UNIOP00003"),xmPushButtonGadgetClass, pw[i].form,
                                      XmNtopAttachment, XmATTACH_WIDGET,
                                      XmNtopWidget, pw[i].popup_message_data,
                                      XmNtopOffset, 10,
                                      XmNbottomAttachment, XmATTACH_FORM,
                                      XmNbottomOffset, 5,
                                      XmNleftAttachment, XmATTACH_POSITION,
                                      XmNleftPosition, 2,
                                      XmNrightAttachment, XmATTACH_POSITION,
                                      XmNrightPosition, 3,
                                      XmNbackground, colors[0xff],
                                      XmNfontList, fontlist1,
                                      NULL);

            sprintf(pw[i].name,"%d",i);

            msg_str=XmStringCreateLtoR(message,XmFONTLIST_DEFAULT_TAG);
            XtVaSetValues(pw[i].popup_message_data,XmNlabelString,msg_str,NULL);
            XmStringFree(msg_str);

            XtAddCallback(pw[i].button_close, XmNactivateCallback, popup_message_destroy_shell,(XtPointer)pw[i].name);

            delw = XmInternAtom(XtDisplay(pw[i].popup_message_dialog),"WM_DELETE_WINDOW", FALSE);

            XmAddWMProtocolCallback(pw[i].popup_message_dialog, delw, popup_message_destroy_shell, (XtPointer)pw[i].name);

            pos_dialog(pw[i].popup_message_dialog);

            XtManageChild(pw[i].form);
            XtManageChild(pw[i].pane);

end_critical_section(&popup_message_dialog_lock, "popup_gui.c:popup_message" );

            XtPopup(pw[i].popup_message_dialog,XtGrabNone);

// An half-hearted attempt at fixing the problem where a popup
// comes up extremely small.  Commenting out the below so we can
// change the size if necessary to read the message.
//            fix_dialog_size(pw[i].popup_message_dialog);

            pw[i].sec_opened=sec_now();
        }
    }
}