static pvStat wait_complete( pvEventType evtype, SS_ID ss, PVREQ **req, DBCHAN *dbch, PVMETA *meta, double tmo) { const char *call = evtype == pvEventGet ? "pvGet" : "pvPut"; while (*req) { switch (epicsEventWaitWithTimeout(ss->syncSem, tmo)) { case epicsEventWaitOK: break; case epicsEventWaitTimeout: *req = NULL; /* cancel the request */ completion_timeout(evtype, meta); return meta->status; case epicsEventWaitError: errlogSevPrintf(errlogFatal, "%s: epicsEventWaitWithTimeout() failure\n", call); *req = NULL; /* cancel the request */ completion_failure(evtype, meta); return meta->status; } } return check_connected(dbch, meta); }
void addons_client::send_request(const config& request, config& response) { check_connected(); response.clear(); this->conn_->transfer(request, response); }
/* * Return whether the last get completed. In safe mode, as a * side effect, copy value from shared buffer to state set local buffer. */ epicsShareFunc boolean seq_pvGetComplete( SS_ID ss, CH_ID chId) { PROG *sp = ss->prog; CHAN *ch = sp->chan + chId; if (!ch->dbch) { /* Anonymous PVs always complete immediately */ if (!optTest(sp, OPT_SAFE)) errlogSevPrintf(errlogMajor, "pvGetComplete(%s): user error (not assigned to a PV)\n", ch->varName); return TRUE; } else if (!ss->getReq[chId]) { pvStat status = check_connected(ch->dbch, metaPtr(ch,ss)); if (status == pvStatOK && optTest(sp, OPT_SAFE)) { /* In safe mode, copy value and meta data from shared buffer to ss local buffer. */ /* Copy regardless of whether dirty flag is set or not */ ss_read_buffer(ss, ch, FALSE); } return TRUE; } return FALSE; }
static void execute_commands(struct command *commands, const char *unpacker_error, struct shallow_info *si, const struct string_list *push_options) { struct check_connected_options opt = CHECK_CONNECTED_INIT; struct command *cmd; unsigned char sha1[20]; struct iterate_data data; struct async muxer; int err_fd = 0; if (unpacker_error) { for (cmd = commands; cmd; cmd = cmd->next) cmd->error_string = "unpacker error"; return; } if (use_sideband) { memset(&muxer, 0, sizeof(muxer)); muxer.proc = copy_to_sideband; muxer.in = -1; if (!start_async(&muxer)) err_fd = muxer.in; /* ...else, continue without relaying sideband */ } data.cmds = commands; data.si = si; opt.err_fd = err_fd; opt.progress = err_fd && !quiet; if (check_connected(iterate_receive_command_list, &data, &opt)) set_connectivity_errors(commands, si); if (use_sideband) finish_async(&muxer); reject_updates_to_hidden(commands); if (run_receive_hook(commands, "pre-receive", 0, push_options)) { for (cmd = commands; cmd; cmd = cmd->next) { if (!cmd->error_string) cmd->error_string = "pre-receive hook declined"; } return; } check_aliased_updates(commands); free(head_name_to_free); head_name = head_name_to_free = resolve_refdup("HEAD", 0, sha1, NULL); if (use_atomic) execute_commands_atomic(commands, si); else execute_commands_non_atomic(commands, si); if (shallow_update) warn_if_skipped_connectivity_check(commands, si); }
/* * Return whether the last get completed. In safe mode, as a * side effect, copy value from shared buffer to state set local buffer. */ epicsShareFunc boolean epicsShareAPI seq_pvGetComplete(SS_ID ss, VAR_ID varId) { epicsEventId getSem = ss->getSemId[varId]; SPROG *sp = ss->sprog; CHAN *ch = sp->chan + varId; pvStat status; if (!ch->dbch) { /* Anonymous PVs always complete immediately */ if (!(sp->options & OPT_SAFE)) errlogSevPrintf(errlogMajor, "pvGetComplete(%s): user error (variable not assigned)\n", ch->varName); return TRUE; } if (!ss->getReq[varId]) { errlogSevPrintf(errlogMinor, "pvGetComplete(%s): no pending get request for this variable\n", ch->varName); return TRUE; } switch (epicsEventTryWait(getSem)) { case epicsEventWaitOK: ss->getReq[varId] = NULL; epicsEventSignal(getSem); status = check_connected(ch->dbch, metaPtr(ch,ss)); /* TODO: returning either TRUE or FALSE here seems wrong. We return TRUE, so that state sets don't hang. Still means that user code has to check status by calling pvStatus and/or pvMessage. */ if (status) return TRUE; /* In safe mode, copy value and meta data from shared buffer to ss local buffer. */ if (sp->options & OPT_SAFE) /* Copy regardless of whether dirty flag is set or not */ ss_read_buffer(ss, ch, FALSE); return TRUE; case epicsEventWaitTimeout: return FALSE; case epicsEventWaitError: ss->getReq[varId] = NULL; epicsEventSignal(getSem); errlogSevPrintf(errlogFatal, "pvGetComplete: " "epicsEventTryWait(getSemId[%d]) failure\n", varId); default: /* pacify gcc which does not understand the we checked all possibilities */ return FALSE; } }
Int rec( const Int& cur ) { Int res = std::numeric_limits<Int>::min(); for ( auto i = cur; i < N; ++ i ) { if ( ! check_connected(i) ) continue; used[i] = true; cnt ++; max(res, std::max(get_sum(), rec(i + 1))); cnt --; used[i] = false; } return res; }
struct ref *fetch_pack(struct fetch_pack_args *args, int fd[], struct child_process *conn, const struct ref *ref, const char *dest, struct ref **sought, int nr_sought, struct oid_array *shallow, char **pack_lockfile, enum protocol_version version) { struct ref *ref_cpy; struct shallow_info si; fetch_pack_setup(); if (nr_sought) nr_sought = remove_duplicates_in_refs(sought, nr_sought); if (!ref) { packet_flush(fd[1]); die(_("no matching remote head")); } prepare_shallow_info(&si, shallow); if (version == protocol_v2) ref_cpy = do_fetch_pack_v2(args, fd, ref, sought, nr_sought, pack_lockfile); else ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought, &si, pack_lockfile); reprepare_packed_git(the_repository); if (!args->cloning && args->deepen) { struct check_connected_options opt = CHECK_CONNECTED_INIT; struct ref *iterator = ref_cpy; opt.shallow_file = alternate_shallow_file; if (args->deepen) opt.is_deepening_fetch = 1; if (check_connected(iterate_ref_map, &iterator, &opt)) { error(_("remote did not send all necessary objects")); free_refs(ref_cpy); ref_cpy = NULL; rollback_lock_file(&shallow_lock); goto cleanup; } args->connectivity_checked = 1; } update_shallow(args, sought, nr_sought, &si); cleanup: clear_shallow_info(&si); return ref_cpy; }
void addons_client::wait_for_transfer_done(const std::string& status_message) { check_connected(); if(!stat_) { stat_ = new gui2::tnetwork_transmission(*conn_, _("Add-ons Manager"), status_message); } else { stat_->set_subtitle(status_message); } if(!stat_->show(disp_.video())) { // Notify the caller chain that the user aborted the operation. throw user_exit(); } }
static void set_connectivity_errors(struct command *commands, struct shallow_info *si) { struct command *cmd; for (cmd = commands; cmd; cmd = cmd->next) { struct command *singleton = cmd; if (shallow_update && si->shallow_ref[cmd->index]) /* to be checked in update_shallow_ref() */ continue; if (!check_connected(command_singleton_iterator, &singleton, NULL)) continue; cmd->error_string = "missing necessary objects"; } }
static void update_remote_refs(const struct ref *refs, const struct ref *mapped_refs, const struct ref *remote_head_points_at, const char *branch_top, const char *msg, struct transport *transport, int check_connectivity) { const struct ref *rm = mapped_refs; if (check_connectivity) { struct check_connected_options opt = CHECK_CONNECTED_INIT; opt.transport = transport; opt.progress = transport->progress; if (check_connected(iterate_ref_map, &rm, &opt)) die(_("remote did not send all necessary objects")); } if (refs) { write_remote_refs(mapped_refs); if (option_single_branch) write_followtags(refs, msg); } if (remote_head_points_at && !option_bare) { struct strbuf head_ref = STRBUF_INIT; strbuf_addstr(&head_ref, branch_top); strbuf_addstr(&head_ref, "HEAD"); if (create_symref(head_ref.buf, remote_head_points_at->peer_ref->name, msg) < 0) die(_("unable to update %s"), head_ref.buf); strbuf_release(&head_ref); } }
static int update_shallow_ref(struct command *cmd, struct shallow_info *si) { static struct lock_file shallow_lock; struct sha1_array extra = SHA1_ARRAY_INIT; struct check_connected_options opt = CHECK_CONNECTED_INIT; uint32_t mask = 1 << (cmd->index % 32); int i; trace_printf_key(&trace_shallow, "shallow: update_shallow_ref %s\n", cmd->ref_name); for (i = 0; i < si->shallow->nr; i++) if (si->used_shallow[i] && (si->used_shallow[i][cmd->index / 32] & mask) && !delayed_reachability_test(si, i)) sha1_array_append(&extra, si->shallow->sha1[i]); setup_alternate_shallow(&shallow_lock, &opt.shallow_file, &extra); if (check_connected(command_singleton_iterator, cmd, &opt)) { rollback_lock_file(&shallow_lock); sha1_array_clear(&extra); return -1; } commit_lock_file(&shallow_lock); /* * Make sure setup_alternate_shallow() for the next ref does * not lose these new roots.. */ for (i = 0; i < extra.nr; i++) register_shallow(extra.sha1[i]); si->shallow_ref[cmd->index] = 0; sha1_array_clear(&extra); return 0; }
/* * Return whether the last put completed. */ static boolean seq_pvSinglePutComplete( SS_ID ss, CH_ID chId) { PROG *sp = ss->prog; CHAN *ch = sp->chan + chId; if (!ch->dbch) { /* Anonymous PVs always complete immediately */ if (!(sp->options & OPT_SAFE)) errlogSevPrintf(errlogMajor, "pvPutComplete(%s): user error (not assigned to a PV)\n", ch->varName); return TRUE; } else if (!ss->putReq[chId]) { check_connected(ch->dbch, metaPtr(ch,ss)); return TRUE; } return FALSE; }
static pvStat check_pending( pvEventType evtype, SS_ID ss, PVREQ **req, const char *varName, DBCHAN *dbch, PVMETA *meta, enum compType compType, double tmo) { const char *call = evtype == pvEventGet ? "pvGet" : "pvPut"; assert(evtype != pvEventMonitor); if (compType == SYNC) { if (tmo <= 0.0) { errlogSevPrintf(errlogMajor, "%s(%s,SYNC,%f): user error (timeout must be positive)\n", call, varName, tmo); return pvStatERROR; } while (*req) { /* a request is already pending (must be an async request) */ double before, after; pvStat status; pvTimeGetCurrentDouble(&before); switch (epicsEventWaitWithTimeout(ss->syncSem, tmo)) { case epicsEventWaitOK: status = check_connected(dbch, meta); if (status != pvStatOK) return status; pvTimeGetCurrentDouble(&after); tmo -= (after - before); if (tmo > 0.0) break; /* else: fall through to timeout */ case epicsEventWaitTimeout: errlogSevPrintf(errlogMajor, "%s(ss %s, var %s, pv %s): failed (timeout " "waiting for other %s requests to finish)\n", call, ss->ssName, varName, dbch->dbName, call ); completion_timeout(evtype, meta); return meta->status; case epicsEventWaitError: errlogSevPrintf(errlogFatal, "%s: epicsEventWaitWithTimeout() failure\n", call); completion_failure(evtype, meta); return meta->status; } } } else if (compType == ASYNC) { if (*req) { errlogSevPrintf(errlogMajor, "%s(ss %s, var %s, pv %s): user error " "(there is already a %s pending for this channel/" "state set combination)\n", call, ss->ssName, varName, dbch->dbName, call ); return pvStatERROR; } } return pvStatOK; }
/* * Return whether the last put completed. */ epicsShareFunc boolean epicsShareAPI seq_pvPutComplete( SS_ID ss, VAR_ID varId, unsigned length, boolean any, boolean *complete) { SPROG *sp = ss->sprog; boolean anyDone = FALSE, allDone = TRUE; unsigned n; for (n = 0; n < length; n++) { epicsEventId putSem = ss->putSemId[varId+n]; boolean done = FALSE; CHAN *ch = sp->chan + varId + n; if (!ch->dbch) { /* Anonymous PVs always complete immediately */ if (!(sp->options & OPT_SAFE)) errlogSevPrintf(errlogMajor, "pvPutComplete(%s): user error (variable not assigned)\n", ch->varName); done = TRUE; } else if (!ss->putReq[varId]) { errlogSevPrintf(errlogMinor, "pvPutComplete(%s): no pending put request for this variable\n", ch->varName); done = TRUE; } else { switch (epicsEventTryWait(putSem)) { case epicsEventWaitOK: ss->putReq[varId] = NULL; epicsEventSignal(putSem); check_connected(ch->dbch, metaPtr(ch,ss)); /* TODO: returning either TRUE or FALSE here seems wrong. We return TRUE, so that state sets don't hang. Still means that user code has to check status by calling pvStatus and/or pvMessage. */ done = TRUE; break; case epicsEventWaitTimeout: break; case epicsEventWaitError: ss->putReq[varId] = NULL; epicsEventSignal(putSem); errlogSevPrintf(errlogFatal, "pvPutComplete(%s): " "epicsEventTryWait(putSem[%d]) failure\n", ch->varName, varId); break; } } anyDone = anyDone || done; allDone = allDone && done; if (complete) { complete[n] = done; } else if (any && done) { break; } } DEBUG("pvPutComplete: varId=%u, length=%u, anyDone=%u, allDone=%u\n", varId, length, anyDone, allDone); return any?anyDone:allDone; }
/* * Put a variable's value to a PV, with timeout. */ epicsShareFunc pvStat seq_pvPutTmo(SS_ID ss, CH_ID chId, enum compType compType, double tmo) { PROG *sp = ss->prog; CHAN *ch = sp->chan + chId; pvStat status; unsigned count; char *var = valPtr(ch,ss); /* ptr to value */ PVREQ *req; DBCHAN *dbch = ch->dbch; PVMETA *meta = metaPtr(ch,ss); DEBUG("pvPut: pv name=%s, var=%p\n", dbch ? dbch->dbName : "<anonymous>", var); /* First handle anonymous PV (safe mode only) */ if (optTest(sp, OPT_SAFE) && !dbch) { anonymous_put(ss, ch); return pvStatOK; } if (!dbch) { errlogSevPrintf(errlogMajor, "pvPut(%s): user error (not assigned to a PV)\n", ch->varName ); return pvStatERROR; } /* Check for channel connected */ status = check_connected(dbch, meta); if (status != pvStatOK) return status; /* Determine whether to perform synchronous, asynchronous, or plain put ((+a) option was never honored for put, so DEFAULT means fire-and-forget) */ status = check_pending(pvEventPut, ss, ss->putReq + chId, ch->varName, dbch, meta, compType, tmo); if (status != pvStatOK) return status; /* Determine number of elements to put (don't try to put more than db count) */ count = dbch->dbCount; /* Perform the PV put operation (either non-blocking or with a callback routine specified) */ if (compType == DEFAULT) { status = pvVarPutNoBlock( &dbch->pvid, /* PV id */ ch->type->putType, /* data type */ count, /* element count */ (pvValue *)var); /* data value */ if (status != pvStatOK) { pv_call_failure(dbch, meta, status); errlogSevPrintf(errlogFatal, "pvPut(var %s, pv %s): pvVarPutNoBlock() failure: %s\n", ch->varName, dbch->dbName, pvVarGetMess(dbch->pvid)); return status; } } else { /* Allocate and initialize a pv request */ req = (PVREQ *)freeListMalloc(sp->pvReqPool); req->ss = ss; req->ch = ch; assert(ss->putReq[chId] == NULL); ss->putReq[chId] = req; status = pvVarPutCallback( &dbch->pvid, /* PV id */ ch->type->putType, /* data type */ count, /* element count */ (pvValue *)var, /* data value */ req); /* user arg */ if (status != pvStatOK) { pv_call_failure(dbch, meta, status); errlogSevPrintf(errlogFatal, "pvPut(var %s, pv %s): pvVarPutCallback() failure: %s\n", ch->varName, dbch->dbName, pvVarGetMess(dbch->pvid)); ss->putReq[chId] = NULL; /* cancel the request */ freeListFree(sp->pvReqPool, req); check_connected(dbch, meta); return status; } if (compType == SYNC) /* wait for completion */ { pvSysFlush(sp->pvSys); status = wait_complete(pvEventPut, ss, ss->putReq + chId, dbch, meta, tmo); if (status != pvStatOK) return status; } } return pvStatOK; }
/* * Get value from a channel, with timeout. */ epicsShareFunc pvStat seq_pvGetTmo(SS_ID ss, CH_ID chId, enum compType compType, double tmo) { PROG *sp = ss->prog; CHAN *ch = sp->chan + chId; pvStat status; PVREQ *req; DBCHAN *dbch = ch->dbch; PVMETA *meta = metaPtr(ch,ss); /* Anonymous PV and safe mode, just copy from shared buffer. Note that completion is always immediate, so no distinction between SYNC and ASYNC needed. See also pvGetComplete. */ if (optTest(sp, OPT_SAFE) && !dbch) { /* Copy regardless of whether dirty flag is set or not */ ss_read_buffer(ss, ch, FALSE); return pvStatOK; } /* No named PV and traditional mode => user error */ if (!dbch) { errlogSevPrintf(errlogMajor, "pvGet(%s): user error (not assigned to a PV)\n", ch->varName ); return pvStatERROR; } if (compType == DEFAULT) { compType = optTest(sp, OPT_ASYNC) ? ASYNC : SYNC; } status = check_pending(pvEventGet, ss, ss->getReq + chId, ch->varName, dbch, meta, compType, tmo); if (status != pvStatOK) return status; /* Allocate and initialize a pv request */ req = (PVREQ *)freeListMalloc(sp->pvReqPool); req->ss = ss; req->ch = ch; assert(ss->getReq[chId] == NULL); ss->getReq[chId] = req; /* Perform the PV get operation with a callback routine specified. Requesting more than db channel has available is ok. */ status = pvVarGetCallback( &dbch->pvid, /* PV id */ ch->type->getType, /* request type */ ch->count, /* element count */ req); /* user arg */ if (status != pvStatOK) { pv_call_failure(dbch, meta, status); errlogSevPrintf(errlogFatal, "pvGet(var %s, pv %s): pvVarGetCallback() failure: %s\n", ch->varName, dbch->dbName, pvVarGetMess(dbch->pvid)); ss->getReq[chId] = NULL; /* cancel the request */ freeListFree(sp->pvReqPool, req); check_connected(dbch, meta); return status; } /* Synchronous: wait for completion */ if (compType == SYNC) { pvSysFlush(sp->pvSys); status = wait_complete(pvEventGet, ss, ss->getReq + chId, dbch, meta, tmo); if (status != pvStatOK) return status; if (optTest(sp, OPT_SAFE)) /* Copy regardless of whether dirty flag is set or not */ ss_read_buffer(ss, ch, FALSE); } return pvStatOK; }
/* * Get value from a channel. * TODO: add optional timeout argument. */ epicsShareFunc pvStat epicsShareAPI seq_pvGet(SS_ID ss, VAR_ID varId, enum compType compType) { SPROG *sp = ss->sprog; CHAN *ch = sp->chan + varId; pvStat status; PVREQ *req; epicsEventId getSem = ss->getSemId[varId]; DBCHAN *dbch = ch->dbch; PVMETA *meta = metaPtr(ch,ss); double tmo = seq_sync_timeout; /* Anonymous PV and safe mode, just copy from shared buffer. Note that completion is always immediate, so no distinction between SYNC and ASYNC needed. See also pvGetComplete. */ if ((sp->options & OPT_SAFE) && !dbch) { /* Copy regardless of whether dirty flag is set or not */ ss_read_buffer(ss, ch, FALSE); return pvStatOK; } /* No named PV and traditional mode => user error */ if (!dbch) { errlogSevPrintf(errlogMajor, "pvGet(%s): user error (variable not assigned)\n", ch->varName ); return pvStatERROR; } if (compType == DEFAULT) { compType = (sp->options & OPT_ASYNC) ? ASYNC : SYNC; } if (compType == SYNC) { double before, after; pvTimeGetCurrentDouble(&before); switch (epicsEventWaitWithTimeout(getSem, tmo)) { case epicsEventWaitOK: status = check_connected(dbch, meta); if (status) return epicsEventSignal(getSem), status; pvTimeGetCurrentDouble(&after); tmo -= (after - before); break; case epicsEventWaitTimeout: errlogSevPrintf(errlogMajor, "pvGet(ss %s, var %s, pv %s): failed (timeout " "waiting for other get requests to finish)\n", ss->ssName, ch->varName, dbch->dbName ); return pvStatERROR; case epicsEventWaitError: /* try to recover */ ss->getReq[varId] = NULL; epicsEventSignal(getSem); errlogSevPrintf(errlogFatal, "pvGet: epicsEventWaitWithTimeout() failure\n"); return pvStatERROR; } } else if (compType == ASYNC) { switch (epicsEventTryWait(getSem)) { case epicsEventWaitOK: if (ss->getReq[varId] != NULL) { /* previous request timed out but user did not call pvGetComplete */ ss->getReq[varId] = NULL; } status = check_connected(dbch, meta); if (status) return epicsEventSignal(getSem), status; break; case epicsEventWaitTimeout: errlogSevPrintf(errlogMajor, "pvGet(ss %s, var %s, pv %s): user error " "(there is already a get pending for this variable/" "state set combination)\n", ss->ssName, ch->varName, dbch->dbName ); return pvStatERROR; case epicsEventWaitError: /* try to recover */ ss->getReq[varId] = NULL; epicsEventSignal(getSem); errlogSevPrintf(errlogFatal, "pvGet: epicsEventTryWait() failure\n"); return pvStatERROR; } } /* Allocate and initialize a pv request */ req = (PVREQ *)freeListMalloc(sp->pvReqPool); req->ss = ss; req->ch = ch; assert(ss->getReq[varId] == NULL); ss->getReq[varId] = req; /* Perform the PV get operation with a callback routine specified. Requesting more than db channel has available is ok. */ status = pvVarGetCallback( dbch->pvid, /* PV id */ ch->type->getType, /* request type */ ch->count, /* element count */ seq_get_handler, /* callback handler */ req); /* user arg */ if (status != pvStatOK) { meta->status = pvStatERROR; meta->severity = pvSevrMAJOR; meta->message = "get failure"; errlogSevPrintf(errlogFatal, "pvGet(var %s, pv %s): pvVarGetCallback() failure: %s\n", ch->varName, dbch->dbName, pvVarGetMess(dbch->pvid)); ss->getReq[varId] = NULL; freeListFree(sp->pvReqPool, req); epicsEventSignal(getSem); check_connected(dbch, meta); return status; } /* Synchronous: wait for completion */ if (compType == SYNC) { epicsEventWaitStatus event_status; pvSysFlush(sp->pvSys); event_status = epicsEventWaitWithTimeout(getSem, tmo); ss->getReq[varId] = NULL; epicsEventSignal(getSem); switch (event_status) { case epicsEventWaitOK: status = check_connected(dbch, meta); if (status) return status; if (sp->options & OPT_SAFE) /* Copy regardless of whether dirty flag is set or not */ ss_read_buffer(ss, ch, FALSE); break; case epicsEventWaitTimeout: meta->status = pvStatTIMEOUT; meta->severity = pvSevrMAJOR; meta->message = "get completion timeout"; return meta->status; case epicsEventWaitError: meta->status = pvStatERROR; meta->severity = pvSevrMAJOR; meta->message = "get completion failure"; return meta->status; } } return pvStatOK; }
int main(void) { SOCKET bcast_s, server_s; int connected = 0, disconnect = 0; /* Setup Hardware */ init_hw(); /* Test SPI and PWM */ #if CONFIG_TEST_HW #if CONFIG_BOARD == CONFIG_BOARD_ADC trigger_isr_start(dspi_read); #endif #if CONFIG_BOARD == CONFIG_BOARD_PWM pwm_start(); #endif while(1); #endif /* Initialise 7 Seg */ sevenseg_set(CONFIG_7SEG_DEFAULT,DP_0); sevenseg_init(); /* Initialise UART */ fnet_cpu_serial_init(FNET_CFG_CPU_SERIAL_PORT_DEFAULT, 115200); /* Clear some screen */ fnet_printf("\n\n\n"); /* Print board type and firmware version */ fnet_printf("Board Type: %s Firmware compiled %s %s \n", CONFIG_BOARD_TYPE_STRING, __TIME__, __DATE__); /* Initialise FNET stack */ init_fnet(); /* Set MAC address based on K60 UID*/ set_mac_address(); /* Wait for Ethernet connection */ fnet_printf("Waiting for Connection \n"); sevenseg_set(CONFIG_7SEG_DEFAULT,DP_1); /* First dot = waiting for connection */ while (!check_connected()) { fnet_timer_delay(FNET_TIMER_TICK_IN_SEC * 1); /* 1 Sec */ fnet_printf("."); /* Print some errors */ } /* Wait for DHCP server, if it fails use link local */ wait_dhcp(CONFIG_DHCP_TRIES); /* Print current IP address */ fnet_printf("Current IP Address:"); print_cur_ip(); fnet_printf("\n"); sevenseg_set(CONFIG_7SEG_DEFAULT,DP_2); /* Second dot = have IP Address */ /* Start UDP receiver */ bcast_s = bcast_setup_listener(CONFIG_BCAST_PORT); if (bcast_s == -1) { fnet_printf("BCAST: Error, could not initialise port \n"); while (1); } sevenseg_set(CONFIG_7SEG_DEFAULT,DP_3); /* Third dot = waiting for UDP */ /* MAIN LOOP */ while (1) { /* CONNECT IF NEEDED */ if(!connected) { connected = netprot_connect(bcast_s, &server_s); #if CONFIG_BOARD == CONFIG_BOARD_PWM if(connected) { sevenseg_set("8888",DP_0); /* Change the screen, this will do for now */ } #endif fnet_poll_services(); /* Poll DHCP while unconnected */ } /* WHEN CONNECTED */ if (connected) { int sent = 0, err; /* Check for disconnection */ if (disconnect) { disconnect = 0; /* Reset */ netprot_goodbye(&server_s); /* Flush UDP port to prevent reconnecting to dead server */ bcast_flush(bcast_s); sevenseg_set(CONFIG_7SEG_DEFAULT,DP_3); /* Third dot = waiting for UDP */ /* Stop what you are doing */ #if CONFIG_BOARD == CONFIG_BOARD_ADC trigger_isr_stop(); capture_set_empty(); #endif fnet_printf("Server Disconnected \n"); connected = 0; continue; } /* Send data first if we are a capture type board */ #if CONFIG_CAPTURE_SUPPORT sent = netprot_send_capture(server_s); if (sent<0) { /* Error - Disconnect */ disconnect = 1; continue; } #endif /* Get commands */ if (sent <= 0) { /* We have sent nothing or error */ err = netprot_get_commands(server_s); if (err) { /* Error - Disconnect */ disconnect = 1; continue; } } } } /* END OF MAIN LOOP */ /* Should never end up here */ return 0; }
struct ref *fetch_pack(struct fetch_pack_args *args, int fd[], struct child_process *conn, const struct ref *ref, const char *dest, struct ref **sought, int nr_sought, struct oid_array *shallow, char **pack_lockfile, enum protocol_version version) { struct ref *ref_cpy; struct shallow_info si; fetch_pack_setup(); if (nr_sought) nr_sought = remove_duplicates_in_refs(sought, nr_sought); if (args->no_dependents && !args->filter_options.choice) { /* * The protocol does not support requesting that only the * wanted objects be sent, so approximate this by setting a * "blob:none" filter if no filter is already set. This works * for all object types: note that wanted blobs will still be * sent because they are directly specified as a "want". * * NEEDSWORK: Add an option in the protocol to request that * only the wanted objects be sent, and implement it. */ parse_list_objects_filter(&args->filter_options, "blob:none"); } if (version != protocol_v2 && !ref) { packet_flush(fd[1]); die(_("no matching remote head")); } prepare_shallow_info(&si, shallow); if (version == protocol_v2) ref_cpy = do_fetch_pack_v2(args, fd, ref, sought, nr_sought, pack_lockfile); else ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought, &si, pack_lockfile); reprepare_packed_git(the_repository); if (!args->cloning && args->deepen) { struct check_connected_options opt = CHECK_CONNECTED_INIT; struct ref *iterator = ref_cpy; opt.shallow_file = alternate_shallow_file; if (args->deepen) opt.is_deepening_fetch = 1; if (check_connected(iterate_ref_map, &iterator, &opt)) { error(_("remote did not send all necessary objects")); free_refs(ref_cpy); ref_cpy = NULL; rollback_lock_file(&shallow_lock); goto cleanup; } args->connectivity_checked = 1; } update_shallow(args, sought, nr_sought, &si); cleanup: clear_shallow_info(&si); return ref_cpy; }
/* * Put a variable's value to a PV. */ epicsShareFunc pvStat epicsShareAPI seq_pvPut(SS_ID ss, VAR_ID varId, enum compType compType) { SPROG *sp = ss->sprog; CHAN *ch = sp->chan + varId; pvStat status; unsigned count; char *var = valPtr(ch,ss); /* ptr to value */ PVREQ *req; DBCHAN *dbch = ch->dbch; PVMETA *meta = metaPtr(ch,ss); epicsEventId putSem = ss->putSemId[varId]; double tmo = seq_sync_timeout; DEBUG("pvPut: pv name=%s, var=%p\n", dbch ? dbch->dbName : "<anonymous>", var); /* First handle anonymous PV (safe mode only) */ if ((sp->options & OPT_SAFE) && !dbch) { anonymous_put(ss, ch); return pvStatOK; } if (!dbch) { errlogSevPrintf(errlogMajor, "pvPut(%s): user error (variable not assigned)\n", ch->varName ); return pvStatERROR; } /* Check for channel connected */ status = check_connected(dbch, meta); if (status) return status; /* Determine whether to perform synchronous, asynchronous, or plain put ((+a) option was never honored for put, so DEFAULT means non-blocking and therefore implicitly asynchronous) */ if (compType == SYNC) { double before, after; pvTimeGetCurrentDouble(&before); switch (epicsEventWaitWithTimeout(putSem, tmo)) { case epicsEventWaitOK: pvTimeGetCurrentDouble(&after); tmo -= (after - before); break; case epicsEventWaitTimeout: errlogSevPrintf(errlogMajor, "pvPut(ss %s, var %s, pv %s): failed (timeout " "waiting for other put requests to finish)\n", ss->ssName, ch->varName, dbch->dbName ); return pvStatERROR; case epicsEventWaitError: /* try to recover */ ss->putReq[varId] = NULL; epicsEventSignal(putSem); errlogSevPrintf(errlogFatal, "pvPut: epicsEventWaitWithTimeout() failure\n"); return pvStatERROR; } } else if (compType == ASYNC) { switch (epicsEventTryWait(putSem)) { case epicsEventWaitOK: if (ss->putReq[varId] != NULL) { /* previous request timed out but user did not call pvPutComplete */ ss->putReq[varId] = NULL; } break; case epicsEventWaitTimeout: meta->status = pvStatERROR; meta->severity = pvSevrMAJOR; meta->message = "already one put pending"; status = meta->status; errlogSevPrintf(errlogMajor, "pvPut(ss %s, var %s, pv %s): user error " "(there is already a put pending for this variable/" "state set combination)\n", ss->ssName, ch->varName, dbch->dbName ); return pvStatERROR; case epicsEventWaitError: /* try to recover */ ss->putReq[varId] = NULL; epicsEventSignal(putSem); errlogSevPrintf(errlogFatal, "pvPut: epicsEventTryWait() failure\n"); return pvStatERROR; } } /* Determine number of elements to put (don't try to put more than db count) */ count = dbch->dbCount; /* Perform the PV put operation (either non-blocking or with a callback routine specified) */ if (compType == DEFAULT) { status = pvVarPutNoBlock( dbch->pvid, /* PV id */ ch->type->putType, /* data type */ count, /* element count */ (pvValue *)var); /* data value */ if (status != pvStatOK) { errlogSevPrintf(errlogFatal, "pvPut(var %s, pv %s): pvVarPutNoBlock() failure: %s\n", ch->varName, dbch->dbName, pvVarGetMess(dbch->pvid)); return status; } } else { /* Allocate and initialize a pv request */ req = (PVREQ *)freeListMalloc(sp->pvReqPool); req->ss = ss; req->ch = ch; assert(ss->putReq[varId] == NULL); ss->putReq[varId] = req; status = pvVarPutCallback( dbch->pvid, /* PV id */ ch->type->putType, /* data type */ count, /* element count */ (pvValue *)var, /* data value */ seq_put_handler, /* callback handler */ req); /* user arg */ if (status != pvStatOK) { ss->putReq[varId] = NULL; errlogSevPrintf(errlogFatal, "pvPut(var %s, pv %s): pvVarPutCallback() failure: %s\n", ch->varName, dbch->dbName, pvVarGetMess(dbch->pvid)); freeListFree(sp->pvReqPool, req); epicsEventSignal(putSem); check_connected(dbch, meta); return status; } } /* Synchronous: wait for completion (10s timeout) */ if (compType == SYNC) { epicsEventWaitStatus event_status; pvSysFlush(sp->pvSys); event_status = epicsEventWaitWithTimeout(putSem, tmo); ss->putReq[varId] = NULL; epicsEventSignal(putSem); switch (event_status) { case epicsEventWaitOK: status = check_connected(dbch, meta); if (status) return status; break; case epicsEventWaitTimeout: meta->status = pvStatTIMEOUT; meta->severity = pvSevrMAJOR; meta->message = "put completion timeout"; return meta->status; break; case epicsEventWaitError: meta->status = pvStatERROR; meta->severity = pvSevrMAJOR; meta->message = "put completion failure"; return meta->status; break; } } return pvStatOK; }