bool AccountState::isConnectedOrTemporarilyUnavailable() const { return isConnected() || _state == ServiceUnavailable; }
bool INDI::CCD::updateProperties() { //IDLog("INDI::CCD UpdateProperties isConnected returns %d %d\n",isConnected(),Connected); if(isConnected()) { defineNumber(PrimaryCCD.ImageExposureNP); defineSwitch(PrimaryCCD.AbortExposureSP); defineNumber(PrimaryCCD.ImageFrameNP); defineNumber(PrimaryCCD.ImageBinNP); if(HasGuideHead) { // IDLog("Sending Guider Stuff\n"); defineNumber(GuideCCD.ImageExposureNP); defineSwitch(GuideCCD.AbortExposureSP); defineNumber(GuideCCD.ImageFrameNP); } defineNumber(PrimaryCCD.ImagePixelSizeNP); if(HasGuideHead) { defineNumber(GuideCCD.ImagePixelSizeNP); } defineSwitch(PrimaryCCD.CompressSP); defineBLOB(PrimaryCCD.FitsBP); if(HasGuideHead) { defineSwitch(GuideCCD.CompressSP); defineBLOB(GuideCCD.FitsBP); } if(HasSt4Port) { defineNumber(&GuideNSP); defineNumber(&GuideEWP); } defineSwitch(PrimaryCCD.FrameTypeSP); defineText(ActiveDeviceTP); } else { deleteProperty(PrimaryCCD.ImageFrameNP->name); deleteProperty(PrimaryCCD.ImageBinNP->name); deleteProperty(PrimaryCCD.ImagePixelSizeNP->name); deleteProperty(PrimaryCCD.ImageExposureNP->name); deleteProperty(PrimaryCCD.AbortExposureSP->name); deleteProperty(PrimaryCCD.FitsBP->name); deleteProperty(PrimaryCCD.CompressSP->name); if(HasGuideHead) { deleteProperty(GuideCCD.ImageExposureNP->name); deleteProperty(GuideCCD.AbortExposureSP->name); deleteProperty(GuideCCD.ImageFrameNP->name); deleteProperty(GuideCCD.ImagePixelSizeNP->name); deleteProperty(GuideCCD.FitsBP->name); deleteProperty(GuideCCD.CompressSP->name); } if(HasSt4Port) { deleteProperty(GuideNSP.name); deleteProperty(GuideEWP.name); } deleteProperty(PrimaryCCD.FrameTypeSP->name); deleteProperty(ActiveDeviceTP->name); } return true; }
// returns a char with the current low alarm temperature or // DEVICE_DISCONNECTED for an address char DallasTemperature::getLowAlarmTemp(uint8_t* deviceAddress) { ScratchPad scratchPad; if (isConnected(deviceAddress, scratchPad)) return (char)scratchPad[LOW_ALARM_TEMP]; return DEVICE_DISCONNECTED; }
bool EventSignalBase::needsUpdate(bool all) const { return (!all && flags_.test(BIT_NEED_UPDATE)) || (all && (isConnected() || defaultActionPrevented() || propagationPrevented())); }
CRoom* CRoom::getExitRoom(ExitDirection dir) const { if (isConnected(dir) == false) return NULL; return parent->getRoom(room.exits().Get(dir).leads_to_id()); }
Poco::Any HighRateMagnetometer::getConnected(const std::string&) const { return isConnected(); }
bool EClientSocket::eConnectImpl(int clientId, bool extraAuth, ConnState* stateOutPt) { // resolve host struct hostent* hostEnt = gethostbyname( host().c_str()); if ( !hostEnt) { getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg()); return false; } // create socket m_fd = socket(AF_INET, SOCK_STREAM, 0); // cannot create socket if( m_fd < 0) { getWrapper()->error( NO_VALID_ID, FAIL_CREATE_SOCK.code(), FAIL_CREATE_SOCK.msg()); return false; } // starting to connect to server struct sockaddr_in sa; memset( &sa, 0, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_port = htons( port()); sa.sin_addr.s_addr = ((in_addr*)hostEnt->h_addr)->s_addr; // try to connect if( (connect( m_fd, (struct sockaddr *) &sa, sizeof( sa))) < 0) { // error connecting SocketClose( m_fd); m_fd = -1; getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg()); return false; } getTransport()->fd(m_fd); // set client id setClientId( clientId); setExtraAuth( extraAuth); int res = sendConnectRequest(); if (res < 0 && !handleSocketError()) return false; if( !isConnected()) { if( connState() != CS_DISCONNECTED) { assert( connState() == CS_REDIRECT); if( stateOutPt) { *stateOutPt = connState(); } eDisconnect(); } return false; } // set socket to non-blocking state if ( !SetSocketNonBlocking(m_fd)) { // error setting socket to non-blocking eDisconnect(); getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg()); return false; } assert( connState() == CS_CONNECTED); if( stateOutPt) { *stateOutPt = connState(); } if (!m_asyncEConnect) { EReader reader(this, m_pSignal); while (m_pSignal && !m_serverVersion && isSocketOK()) { reader.checkClient(); m_pSignal->waitForSignal(); reader.processMsgs(); } } // successfully connected return isSocketOK(); }
void TCFS::TimerHit() { static double lastPosition = -1, lastTemperature = -1000; if (!isConnected()) { SetTimer(POLLMS); return; } int f_position = 0; float f_temperature = 0; char response[TCFS_MAX_CMD] = { 0 }; if(!isSimulation() && currentMode != MANUAL) { if (FocusTelemetrySP.sp[1].s == ISS_ON) { LOGF_DEBUG("%s %s",__FUNCTION__, "Telemetry is off"); SetTimer(POLLMS); return; } for(int i=0; i<2; i++) { if (read_tcfs(response) == false) { SetTimer(POLLMS); return; } LOGF_DEBUG("%s Received %s",__FUNCTION__, response); if(sscanf(response, "P=%d", &f_position) == 1) { currentPosition = f_position; if (lastPosition != currentPosition) { lastPosition = currentPosition; IDSetNumber(&FocusAbsPosNP, nullptr); } } else if(sscanf(response, "T=%f", &f_temperature)==1) { FocusTemperatureNP.np[0].value = f_temperature; if (lastTemperature != FocusTemperatureNP.np[0].value) { lastTemperature = FocusTemperatureNP.np[0].value; IDSetNumber(&FocusTemperatureNP, nullptr); } } } SetTimer(POLLMS); return; } if (FocusGotoSP.s == IPS_BUSY) { ISwitch *sp = IUFindOnSwitch(&FocusGotoSP); if (sp != nullptr && strcmp(sp->name, "FOCUS_CENTER") == 0) { bool rc = read_tcfs(response, true); if (!rc) { SetTimer(POLLMS); return; } if (isSimulation()) strncpy(response, "CENTER", TCFS_MAX_CMD); if (strcmp(response, "CENTER") == 0) { IUResetSwitch(&FocusGotoSP); FocusGotoSP.s = IPS_OK; FocusAbsPosNP.s = IPS_OK; IDSetSwitch(&FocusGotoSP, nullptr); IDSetNumber(&FocusAbsPosNP, nullptr); LOG_INFO("Focuser moved to center position."); } } } switch (FocusAbsPosNP.s) { case IPS_OK: if (FocusModeSP.sp[0].s == ISS_ON) dispatch_command(FPOSRO); if (read_tcfs(response) == false) { SetTimer(POLLMS); return; } if (isSimulation()) snprintf(response, TCFS_MAX_CMD, "P=%04d", (int)simulated_position); sscanf(response, "P=%d", &f_position); currentPosition = f_position; if (lastPosition != currentPosition) { lastPosition = currentPosition; IDSetNumber(&FocusAbsPosNP, nullptr); } break; case IPS_BUSY: if (read_tcfs(response, true) == false) { SetTimer(POLLMS); return; } // Ignore error if (strstr(response, "ER") != nullptr) { LOGF_DEBUG("Received error: %s", response); SetTimer(POLLMS); return; } if (isSimulation()) strncpy(response, "*", 2); if (strcmp(response, "*") == 0) { LOGF_DEBUG("Moving focuser %d steps to position %d.", targetTicks, targetPosition); FocusAbsPosNP.s = IPS_OK; FocusRelPosNP.s = IPS_OK; FocusGotoSP.s = IPS_OK; IDSetNumber(&FocusAbsPosNP, nullptr); IDSetNumber(&FocusRelPosNP, nullptr); IDSetSwitch(&FocusGotoSP, nullptr); } else { FocusAbsPosNP.s = IPS_ALERT; LOGF_ERROR("Unable to read response from focuser #%s#.", response); IDSetNumber(&FocusAbsPosNP, nullptr); } break; default: break; } if (FocusTemperatureNP.s != IPS_IDLE) { // Read Temperature // Manual Mode if (FocusModeSP.sp[0].s == ISS_ON) dispatch_command(FTMPRO); if (read_tcfs(response) == false) { SetTimer(POLLMS); return; } if (isSimulation()) snprintf(response, TCFS_MAX_CMD, "T=%0.1f", simulated_temperature); sscanf(response, "T=%f", &f_temperature); FocusTemperatureNP.np[0].value = f_temperature; if (lastTemperature != FocusTemperatureNP.np[0].value) { lastTemperature = FocusTemperatureNP.np[0].value; IDSetNumber(&FocusTemperatureNP, nullptr); } } SetTimer(POLLMS); }
bool DbUtil::runQuery(const char* sql, const Properties& args, SqlResultSet& rows){ rows.clear(); if (!isConnected()) return false; g_debug << "runQuery: " << endl << " sql: '" << sql << "'" << endl; MYSQL_STMT *stmt= mysql_stmt_init(m_mysql); if (mysql_stmt_prepare(stmt, sql, strlen(sql))) { g_err << "Failed to prepare: " << mysql_error(m_mysql) << endl; return false; } uint params= mysql_stmt_param_count(stmt); MYSQL_BIND bind_param[params]; bzero(bind_param, sizeof(bind_param)); for(uint i= 0; i < mysql_stmt_param_count(stmt); i++) { BaseString name; name.assfmt("%d", i); // Parameters are named 0, 1, 2... if (!args.contains(name.c_str())) { g_err << "param " << i << " missing" << endl; assert(false); } PropertiesType t; Uint32 val_i; const char* val_s; args.getTypeOf(name.c_str(), &t); switch(t) { case PropertiesType_Uint32: args.get(name.c_str(), &val_i); bind_param[i].buffer_type= MYSQL_TYPE_LONG; bind_param[i].buffer= (char*)&val_i; g_debug << " param" << name.c_str() << ": " << val_i << endl; break; case PropertiesType_char: args.get(name.c_str(), &val_s); bind_param[i].buffer_type= MYSQL_TYPE_STRING; bind_param[i].buffer= (char*)val_s; bind_param[i].buffer_length= strlen(val_s); g_debug << " param" << name.c_str() << ": " << val_s << endl; break; default: assert(false); break; } } if (mysql_stmt_bind_param(stmt, bind_param)) { g_err << "Failed to bind param: " << mysql_error(m_mysql) << endl; mysql_stmt_close(stmt); return false; } if (mysql_stmt_execute(stmt)) { g_err << "Failed to execute: " << mysql_error(m_mysql) << endl; mysql_stmt_close(stmt); return false; } /* Update max_length, making it possible to know how big buffers to allocate */ my_bool one= 1; mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*) &one); if (mysql_stmt_store_result(stmt)) { g_err << "Failed to store result: " << mysql_error(m_mysql) << endl; mysql_stmt_close(stmt); return false; } uint row= 0; MYSQL_RES* res= mysql_stmt_result_metadata(stmt); if (res != NULL) { MYSQL_FIELD *fields= mysql_fetch_fields(res); uint num_fields= mysql_num_fields(res); MYSQL_BIND bind_result[num_fields]; bzero(bind_result, sizeof(bind_result)); for (uint i= 0; i < num_fields; i++) { if (is_int_type(fields[i].type)){ bind_result[i].buffer_type= MYSQL_TYPE_LONG; bind_result[i].buffer= malloc(sizeof(int)); } else { uint max_length= fields[i].max_length + 1; bind_result[i].buffer_type= MYSQL_TYPE_STRING; bind_result[i].buffer= malloc(max_length); bind_result[i].buffer_length= max_length; } } if (mysql_stmt_bind_result(stmt, bind_result)){ g_err << "Failed to bind result: " << mysql_error(m_mysql) << endl; mysql_stmt_close(stmt); return false; } while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) { Properties curr(true); for (uint i= 0; i < num_fields; i++){ if (is_int_type(fields[i].type)) curr.put(fields[i].name, *(int*)bind_result[i].buffer); else curr.put(fields[i].name, (char*)bind_result[i].buffer); } rows.put("row", row++, &curr); } mysql_free_result(res); for (uint i= 0; i < num_fields; i++) free(bind_result[i].buffer); } // Save stats in result set rows.put("rows", row); rows.put("affected_rows", mysql_affected_rows(m_mysql)); rows.put("mysql_errno", mysql_errno(m_mysql)); rows.put("mysql_error", mysql_error(m_mysql)); rows.put("mysql_sqlstate", mysql_sqlstate(m_mysql)); rows.put("insert_id", mysql_insert_id(m_mysql)); mysql_stmt_close(stmt); return true; }
void DomeSim::TimerHit() { int nexttimer=1000; if(isConnected() == false) return; // No need to reset timer if we are not connected anymore if (DomeAbsPosNP.s == IPS_BUSY) { if (targetAz > DomeAbsPosN[0].value) { DomeAbsPosN[0].value += DOME_SPEED; } else if (targetAz < DomeAbsPosN[0].value) { DomeAbsPosN[0].value -= DOME_SPEED; } DomeAbsPosN[0].value = range360(DomeAbsPosN[0].value); if (fabs(targetAz - DomeAbsPosN[0].value) <= DOME_SPEED) { DomeAbsPosN[0].value = targetAz; DEBUG(INDI::Logger::DBG_SESSION, "Dome reached requested azimuth angle."); if (getDomeState() == DOME_PARKING) SetParked(true); else if (getDomeState() == DOME_UNPARKING) SetParked(false); else setDomeState(DOME_SYNCED); } IDSetNumber(&DomeAbsPosNP, NULL); } if (DomeShutterSP.s == IPS_BUSY) { if (shutterTimer-- <= 0) { shutterTimer=0; DomeShutterSP.s = IPS_OK; DEBUGF(INDI::Logger::DBG_SESSION, "Shutter is %s.", (DomeShutterS[0].s == ISS_ON ? "open" : "closed")); IDSetSwitch(&DomeShutterSP, NULL); if (getDomeState() == DOME_UNPARKING) SetParked(false); } } SetTimer(nexttimer); // Not all mounts update ra/dec constantly if tracking co-ordinates // This is to ensure our alt/az gets updated even if ra/dec isn't being updated // Once every 10 seconds is more than sufficient // with this added, dome simulator will now correctly track telescope simulator // which does not emit new ra/dec co-ords if they are not changing if(isParked() == false && TimeSinceUpdate++ > 9) { TimeSinceUpdate=0; UpdateMountCoords(); } return; }
bool TCFS::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) { //LOGF_DEBUG("%s %s",__FUNCTION__, me); if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { char response[TCFS_MAX_CMD] = { 0 }; if (!strcmp(FocusPowerSP.name, name)) { IUUpdateSwitch(&FocusPowerSP, states, names, n); bool sleep = false; ISwitch *sp = IUFindOnSwitch(&FocusPowerSP); // Sleep if (!strcmp(sp->name, "FOCUS_SLEEP")) { dispatch_command(FSLEEP); sleep = true; } // Wake Up else dispatch_command(FWAKUP); if (read_tcfs(response) == false) { IUResetSwitch(&FocusPowerSP); FocusPowerSP.s = IPS_ALERT; IDSetSwitch(&FocusPowerSP, "Error reading TCF-S reply."); return true; } if (sleep) { if (isSimulation()) strncpy(response, "ZZZ", TCFS_MAX_CMD); if (strcmp(response, "ZZZ") == 0) { FocusPowerSP.s = IPS_OK; IDSetSwitch(&FocusPowerSP, "Focuser is set into sleep mode."); FocusAbsPosNP.s = IPS_IDLE; IDSetNumber(&FocusAbsPosNP, nullptr); // if (FocusTemperatureNP) { FocusTemperatureNP.s = IPS_IDLE; IDSetNumber(&FocusTemperatureNP, nullptr); } return true; } else { FocusPowerSP.s = IPS_ALERT; IDSetSwitch(&FocusPowerSP, "Focuser sleep mode operation failed. Response: %s.", response); return true; } } else { if (isSimulation()) strncpy(response, "WAKE", TCFS_MAX_CMD); if (strcmp(response, "WAKE") == 0) { FocusPowerSP.s = IPS_OK; IDSetSwitch(&FocusPowerSP, "Focuser is awake."); FocusAbsPosNP.s = IPS_OK; IDSetNumber(&FocusAbsPosNP, nullptr); // if (FocusTemperatureNP) { FocusTemperatureNP.s = IPS_OK; IDSetNumber(&FocusTemperatureNP, nullptr); } return true; } else { FocusPowerSP.s = IPS_ALERT; IDSetSwitch(&FocusPowerSP, "Focuser wake up operation failed. Response: %s", response); return true; } } } // Do not process any command if focuser is asleep if (isConnected() && FocusPowerSP.sp[0].s == ISS_ON) { ISwitchVectorProperty *svp = getSwitch(name); if (svp) { svp->s = IPS_IDLE; LOG_WARN("Focuser is still in sleep mode. Wake up in order to issue commands."); IDSetSwitch(svp, nullptr); } return true; } if (!strcmp(FocusModeSP.name, name)) { IUUpdateSwitch(&FocusModeSP, states, names, n); FocusModeSP.s = IPS_OK; ISwitch *sp = IUFindOnSwitch(&FocusModeSP); if (!strcmp(sp->name, "Manual")) { if (!isSimulation() && !SetManualMode()) { IUResetSwitch(&FocusModeSP); FocusModeSP.s = IPS_ALERT; IDSetSwitch(&FocusModeSP, "Error switching to manual mode. No reply from TCF-S. Try again."); return true; } } else if (!strcmp(sp->name, "Auto A")) { dispatch_command(FAMODE); read_tcfs(response); if (!isSimulation() && strcmp(response, "A") != 0) { IUResetSwitch(&FocusModeSP); FocusModeSP.s = IPS_ALERT; IDSetSwitch(&FocusModeSP, "Error switching to Auto Mode A. No reply from TCF-S. Try again."); return true; } LOG_INFO("Entered Auto Mode A"); currentMode = MODE_A; } else { dispatch_command(FBMODE); read_tcfs(response); if (!isSimulation() && strcmp(response, "B") != 0) { IUResetSwitch(&FocusModeSP); FocusModeSP.s = IPS_ALERT; IDSetSwitch(&FocusModeSP, "Error switching to Auto Mode B. No reply from TCF-S. Try again."); return true; } LOG_INFO("Entered Auto Mode B"); currentMode = MODE_B; } IDSetSwitch(&FocusModeSP, nullptr); return true; } if (!strcmp(FocusGotoSP.name, name)) { if (FocusModeSP.sp[0].s != ISS_ON) { FocusGotoSP.s = IPS_IDLE; IDSetSwitch(&FocusGotoSP, nullptr); LOG_WARN("The focuser can only be moved in Manual mode."); return false; } IUUpdateSwitch(&FocusGotoSP, states, names, n); FocusGotoSP.s = IPS_BUSY; ISwitch *sp = IUFindOnSwitch(&FocusGotoSP); // Min if (!strcmp(sp->name, "FOCUS_MIN")) { targetTicks = currentPosition; MoveRelFocuser(FOCUS_INWARD, currentPosition); IDSetSwitch(&FocusGotoSP, "Moving focuser to minimum position..."); } // Center else if (!strcmp(sp->name, "FOCUS_CENTER")) { dispatch_command(FCENTR); FocusAbsPosNP.s = FocusRelPosNP.s = IPS_BUSY; IDSetNumber(&FocusAbsPosNP, nullptr); IDSetNumber(&FocusRelPosNP, nullptr); IDSetSwitch(&FocusGotoSP, "Moving focuser to center position %d...", isTCFS3 ? 5000 : 3500); return true; } // Max else if (!strcmp(sp->name, "FOCUS_MAX")) { unsigned int delta = 0; delta = FocusAbsPosN[0].max - currentPosition; MoveRelFocuser(FOCUS_OUTWARD, delta); IDSetSwitch(&FocusGotoSP, "Moving focuser to maximum position %g...", FocusAbsPosN[0].max); } // Home else if (!strcmp(sp->name, "FOCUS_HOME")) { dispatch_command(FHOME); read_tcfs(response); if (isSimulation()) strncpy(response, "DONE", TCFS_MAX_CMD); if (strcmp(response, "DONE") == 0) { IUResetSwitch(&FocusGotoSP); FocusGotoSP.s = IPS_OK; IDSetSwitch(&FocusGotoSP, "Moving focuser to new calculated position based on temperature..."); return true; } else { IUResetSwitch(&FocusGotoSP); FocusGotoSP.s = IPS_ALERT; IDSetSwitch(&FocusGotoSP, "Failed to move focuser to home position!"); return true; } } IDSetSwitch(&FocusGotoSP, nullptr); return true; } // handle quiet mode on/off if (!strcmp(FocusTelemetrySP.name, name)) { IUUpdateSwitch(&FocusTelemetrySP, states, names, n); bool quiet = false; ISwitch *sp = IUFindOnSwitch(&FocusTelemetrySP); // Telemetry off if (!strcmp(sp->name, "FOCUS_TELEMETRY_OFF")) { dispatch_command(FQUIET, 1); quiet = true; } // Telemetry On else dispatch_command(FQUIET, 0); if (read_tcfs(response) == false) { IUResetSwitch(&FocusTelemetrySP); FocusTelemetrySP.s = IPS_ALERT; IDSetSwitch(&FocusTelemetrySP, "Error reading TCF-S reply."); return true; } if (isSimulation()) strncpy(response, "DONE", TCFS_MAX_CMD); if (strcmp(response, "DONE") == 0) { FocusTelemetrySP.s = IPS_OK; IDSetSwitch(&FocusTelemetrySP, quiet ? "Focuser Telemetry is off." : "Focuser Telemetry is on."); // if (FocusTemperatureNP) { FocusTemperatureNP.s = quiet?IPS_IDLE:IPS_OK; IDSetNumber(&FocusTemperatureNP, nullptr); } return true; } else { FocusTelemetrySP.s = IPS_ALERT; IDSetSwitch(&FocusTelemetrySP, "Focuser telemetry mode failed. Response: %s.", response); return true; } } } return INDI::Focuser::ISNewSwitch(dev, name, states, names, n); }
void RoboFocus::TimerHit() { if (isConnected() == false) return; double prevPos=currentPosition; double newPos=0; if (FocusAbsPosNP.s == IPS_OK || FocusAbsPosNP.s == IPS_IDLE) { int rc = updateRFPosition(&newPos); if (rc >= 0) { currentPosition = newPos; if (prevPos != currentPosition) IDSetNumber(&FocusAbsPosNP, NULL); } } else if (FocusAbsPosNP.s == IPS_BUSY) { float newPos=0; int nbytes_read=0; char rf_cmd[RF_MAX_CMD] = {0}; //nbytes_read= ReadUntilComplete(rf_cmd, RF_TIMEOUT) ; nbytes_read= ReadResponse(rf_cmd); rf_cmd[ nbytes_read - 1] = 0 ; if (nbytes_read != 9 || (sscanf(rf_cmd, "FD0%5f", &newPos) <= 0)) { DEBUGF(INDI::Logger::DBG_WARNING, "Bogus position: (%#02X %#02X %#02X %#02X %#02X %#02X %#02X %#02X %#02X) - Bytes read: %d", rf_cmd[0], rf_cmd[1], rf_cmd[2], rf_cmd[3], rf_cmd[4], rf_cmd[5], rf_cmd[6], rf_cmd[7], rf_cmd[8], nbytes_read); timerID = SetTimer(POLLMS); return; } else if (nbytes_read < 0) { FocusAbsPosNP.s == IPS_ALERT; DEBUG(INDI::Logger::DBG_ERROR, "Read error! Reconnect and try again."); IDSetNumber(&FocusAbsPosNP, NULL); return; } currentPosition = newPos; if (currentPosition == targetPos) { FocusAbsPosNP.s = IPS_OK; if (FocusRelPosNP.s == IPS_BUSY) { FocusRelPosNP.s = IPS_OK; IDSetNumber(&FocusRelPosNP, NULL); } } IDSetNumber(&FocusAbsPosNP, NULL); if (FocusAbsPosNP.s == IPS_BUSY) { timerID = SetTimer(250); return; } } timerID = SetTimer(POLLMS); }
void DirectShowPlayerService::doRender(QMutexLocker *locker) { m_pendingTasks |= m_executedTasks & (Play | Pause); if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) { control->Stop(); control->Release(); } if (m_pendingTasks & SetAudioOutput) { m_graph->AddFilter(m_audioOutput, L"AudioOutput"); m_pendingTasks ^= SetAudioOutput; m_executedTasks |= SetAudioOutput; } if (m_pendingTasks & SetVideoOutput) { m_graph->AddFilter(m_videoOutput, L"VideoOutput"); m_pendingTasks ^= SetVideoOutput; m_executedTasks |= SetVideoOutput; } IFilterGraph2 *graph = m_graph; graph->AddRef(); QVarLengthArray<IBaseFilter *, 16> filters; m_source->AddRef(); filters.append(m_source); bool rendered = false; HRESULT renderHr = S_OK; while (!filters.isEmpty()) { IEnumPins *pins = 0; IBaseFilter *filter = filters[filters.size() - 1]; filters.removeLast(); if (!(m_pendingTasks & ReleaseFilters) && SUCCEEDED(filter->EnumPins(&pins))) { int outputs = 0; for (IPin *pin = 0; pins->Next(1, &pin, 0) == S_OK; pin->Release()) { PIN_DIRECTION direction; if (pin->QueryDirection(&direction) == S_OK && direction == PINDIR_OUTPUT) { ++outputs; IPin *peer = 0; if (pin->ConnectedTo(&peer) == S_OK) { PIN_INFO peerInfo; if (SUCCEEDED(peer->QueryPinInfo(&peerInfo))) filters.append(peerInfo.pFilter); peer->Release(); } else { locker->unlock(); HRESULT hr; if (SUCCEEDED(hr = graph->RenderEx( pin, /*AM_RENDEREX_RENDERTOEXISTINGRENDERERS*/ 1, 0))) { rendered = true; } else if (renderHr == S_OK || renderHr == VFW_E_NO_DECOMPRESSOR){ renderHr = hr; } locker->relock(); } } } pins->Release(); if (outputs == 0) rendered = true; } filter->Release(); } if (m_audioOutput && !isConnected(m_audioOutput, PINDIR_INPUT)) { graph->RemoveFilter(m_audioOutput); m_executedTasks &= ~SetAudioOutput; } if (m_videoOutput && !isConnected(m_videoOutput, PINDIR_INPUT)) { graph->RemoveFilter(m_videoOutput); m_executedTasks &= ~SetVideoOutput; } graph->Release(); if (!(m_pendingTasks & ReleaseFilters)) { if (rendered) { if (!(m_executedTasks & FinalizeLoad)) m_pendingTasks |= FinalizeLoad; } else { m_pendingTasks = 0; m_graphStatus = InvalidMedia; if (!m_audioOutput && !m_videoOutput) { m_error = QMediaPlayer::ResourceError; m_errorString = QString(); } else { switch (renderHr) { case VFW_E_UNSUPPORTED_AUDIO: case VFW_E_UNSUPPORTED_VIDEO: case VFW_E_UNSUPPORTED_STREAM: m_error = QMediaPlayer::FormatError; m_errorString = QString(); break; default: m_error = QMediaPlayer::ResourceError; m_errorString = QString(); qWarning("DirectShowPlayerService::doRender: Unresolved error code %x", uint(renderHr)); } } QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error))); } m_executedTasks |= Render; } m_loop->wake(); }
void FMS::periodic() { if(isConnected()) { //If it's time then send a heartbeat request if(millis() - fmsLastSeen > FMS_HEARTBEAT_DELAY) //Add stuff to prevent dropped packets maybe idc { disableWatchdogs(); // Make sure watchdogs don't die when checking on heartbeat //Serial.println(F("Checking on heartbeat")); //TODO: dleete this sendPacket(F("HB_LUB")); long hbStarted = millis(); while(str_equals(readLine(), "")) { if(millis() - hbStarted > FMS_HEARTBEAT_TIMEOUT) { connectedToFMS = false; client.close(); Serial.println(F("FMS connection dropped.")); setState(DISABLED); enableWatchdogs(); return; } } fmsLastSeen = millis(); enableWatchdogs(); } //handle packets from fms char* input = readLine(); if(!str_equals(input, "")) { if(str_startsWith(input, "S_S_")) { str_replace(input, "S_S_", ""); if(str_startsWith(input, "A")) { setState(AUTONOMOUS); } else if(str_startsWith(input, "D")) { setState(DISABLED); } else if(str_startsWith(input, "T")) { setState(TELEOP); } sendPacket(F("S_ACK")); } else Serial.println(input); //Something wrong happened so lets output it for debug fmsLastSeen = millis(); } } else { disableWatchdogs(); connect(); enableWatchdogs(); } }
bool EventListenerController::init() { auto listener = [this](Event* event){ auto evtController = static_cast<EventController*>(event); if (evtController->getControllerEventType() == EventController::ControllerEventType::CONNECTION) { if (evtController->isConnected()) { if (this->onConnected) this->onConnected(evtController->getController(), event); } else { if (this->onDisconnected) this->onDisconnected(evtController->getController(), event); } } else { switch (evtController->getControllerEventType()) { case EventController::ControllerEventType::BUTTON_STATUS_CHANGED: { auto button = static_cast<ControllerButtonInput*>(evtController->getControllerElement()); if (this->onButtonPressed && button->isPressed() && !button->isPrevStatusPressed()) { this->onButtonPressed(evtController->getController(), button, event); } else if (this->onButtonReleased && !button->isPressed() && button->isPrevStatusPressed()) { this->onButtonReleased(evtController->getController(), button, event); } if (this->onButtonValueChanged) { this->onButtonValueChanged(evtController->getController(), button, event); } } break; case EventController::ControllerEventType::AXIS_STATUS_CHANGED: { if (this->onAxisValueChanged) { auto axis = static_cast<ControllerAxisInput*>(evtController->getControllerElement()); this->onAxisValueChanged(evtController->getController(), axis, event); } } break; default: CCASSERT(false, "Invalid EventController type"); break; } } }; if (EventListener::init(EventListener::Type::GAME_CONTROLLER, LISTENER_ID, listener)) { return true; } return false; }
void SQLiteConnection::checkConnection() { if( !isConnected() ) throw co::Exception( "Database not connected. Cannot execute command" ); }
void DiagramEndPoint::MessageDragged( BPoint point, uint32 transit, const BMessage *message) { D_MOUSE(("DiagramEndPoint::MessageDragged()\n")); switch (message->what) { case M_WIRE_DRAGGED: { D_MESSAGE(("DiagramEndPoint::MessageDragged(M_WIRE_DRAGGED)\n")); switch (transit) { case B_INSIDE_VIEW: { //PRINT((" -> transit: B_INSIDE_VIEW\n")); // this is a WORK-AROUND caused by the unreliability // of BViews DragMessage() routine !! if (isConnecting()) { break; } else if (isConnected()) { view()->trackWire(point); } /* this should be enough in theory: if (!isConnecting()) { view()->trackWire(point); } //break;*/ } case B_ENTERED_VIEW: { //PRINT((" -> transit: B_ENTERED_VIEW\n")); DiagramEndPoint *endPoint; if ((message->FindPointer("from", reinterpret_cast<void **>(&endPoint)) == B_OK) && (endPoint != this)) { if (connectionRequested(endPoint)) { view()->trackWire(connectionPoint()); if (!isConnecting()) { m_connecting = true; connected(); } } else { view()->trackWire(point); if (isConnecting()) { m_connecting = false; disconnected(); } } } break; } case B_EXITED_VIEW: { //PRINT((" -> transit: B_EXITED_VIEW\n")); if (isConnecting()) { m_connecting = false; disconnected(); } break; } } break; } default: { DiagramItem::MessageDragged(point, transit, message); } } }
void connectToTor() { if (isConnected()) sock_.disconnectFromHost(); sock_.connectToHost(host_[0], host_[1].toInt()); }
bool AnalogInputs::isBalancePortConnected() { return isConnected(Vbalancer); }
// returns temperature in 1/128 degrees C or DEVICE_DISCONNECTED_RAW if the // device's scratch pad cannot be read successfully. // the numeric value of DEVICE_DISCONNECTED_RAW is defined in // DallasTemperature.h. It is a large negative number outside the // operating range of the device int16_t DallasTemperature::getTemp(const uint8_t* deviceAddress) { ScratchPad scratchPad; if (isConnected(deviceAddress, scratchPad)) return calculateTemperature(deviceAddress, scratchPad); return DEVICE_DISCONNECTED_RAW; }
void QSICCD::TimerHit() { long timeleft = 0; double ccdTemp = 0; double coolerPower = 0; if (isConnected() == false) return; // No need to reset timer if we are not connected anymore if (InExposure) { bool imageReady; timeleft = CalcTimeLeft(ExpStart, ExposureRequest); if (timeleft < 1) { QSICam.get_ImageReady(&imageReady); while (!imageReady) { usleep(100); QSICam.get_ImageReady(&imageReady); } /* We're done exposing */ DEBUG(INDI::Logger::DBG_SESSION, "Exposure done, downloading image..."); PrimaryCCD.setExposureLeft(0); InExposure = false; /* grab and save image */ grabImage(); } else { DEBUGF(INDI::Logger::DBG_DEBUG, "Image not ready, time left %ld\n", timeleft); PrimaryCCD.setExposureLeft(timeleft); } } switch (TemperatureNP.s) { case IPS_IDLE: case IPS_OK: try { QSICam.get_CCDTemperature(&ccdTemp); } catch (std::runtime_error err) { TemperatureNP.s = IPS_IDLE; DEBUGF(INDI::Logger::DBG_ERROR, "get_CCDTemperature() failed. %s.", err.what()); IDSetNumber(&TemperatureNP, nullptr); return; } if (fabs(TemperatureN[0].value - ccdTemp) >= TEMP_THRESHOLD) { TemperatureN[0].value = ccdTemp; IDSetNumber(&TemperatureNP, nullptr); } break; case IPS_BUSY: try { QSICam.get_CCDTemperature(&TemperatureN[0].value); } catch (std::runtime_error err) { TemperatureNP.s = IPS_ALERT; DEBUGF(INDI::Logger::DBG_ERROR, "get_CCDTemperature() failed. %s.", err.what()); IDSetNumber(&TemperatureNP, nullptr); return; } if (fabs(TemperatureN[0].value - targetTemperature) <= TEMP_THRESHOLD) TemperatureNP.s = IPS_OK; IDSetNumber(&TemperatureNP, nullptr); break; case IPS_ALERT: break; } switch (CoolerNP.s) { case IPS_IDLE: case IPS_OK: try { QSICam.get_CoolerPower(&coolerPower); } catch (std::runtime_error err) { CoolerNP.s = IPS_IDLE; DEBUGF(INDI::Logger::DBG_ERROR, "get_CoolerPower() failed. %s.", err.what()); IDSetNumber(&CoolerNP, nullptr); return; } if (CoolerN[0].value != coolerPower) { CoolerN[0].value = coolerPower; IDSetNumber(&CoolerNP, nullptr); } if (coolerPower > 0) CoolerNP.s = IPS_BUSY; break; case IPS_BUSY: try { QSICam.get_CoolerPower(&coolerPower); } catch (std::runtime_error err) { CoolerNP.s = IPS_ALERT; DEBUGF(INDI::Logger::DBG_ERROR, "get_CoolerPower() failed. %s.", err.what()); IDSetNumber(&CoolerNP, nullptr); return; } if (coolerPower == 0) CoolerNP.s = IPS_IDLE; CoolerN[0].value = coolerPower; IDSetNumber(&CoolerNP, nullptr); break; case IPS_ALERT: break; } SetTimer(POLLMS); return; }
// returns a char with the current high alarm temperature or // DEVICE_DISCONNECTED for an address char DallasTemperature::getHighAlarmTemp(const uint8_t* deviceAddress) { ScratchPad scratchPad; if (isConnected(deviceAddress, scratchPad)) return (char)scratchPad[HIGH_ALARM_TEMP]; return DEVICE_DISCONNECTED_C; }
const std::string EventSignalBase::createUserEventCall(const std::string& jsObject, const std::string& jsEvent, const std::string& eventName, const std::string& arg1, const std::string& arg2, const std::string& arg3, const std::string& arg4, const std::string& arg5, const std::string& arg6) const { /* * If we aren't connected yet to anything, assume we will be later to * a server-side signal, and expose the signal now. */ if (!this->isExposedSignal() && !isConnected()) const_cast<EventSignalBase*>(this)->exposeSignal(); std::stringstream result; result << javaScript(); if (flags_.test(BIT_SERVER_EVENT)) { WApplication *app = WApplication::instance(); std::string senderId = encodeCmd(); senderId = senderId.substr(0, senderId.length() - eventName.length() - 1); result << app->javaScriptClass() << ".emit('" << senderId; if (!jsObject.empty()) result << "', { name:'" << eventName << "', eventObject:" << jsObject << ", event:" << jsEvent << "}"; else result << "','" << eventName << "'"; if (!arg1.empty()) { result << "," << arg1; if (!arg2.empty()) { result << "," << arg2; if (!arg3.empty()) { result << "," << arg3; if (!arg4.empty()) { result << "," << arg4; if (!arg5.empty()) { result << "," << arg5; if (!arg6.empty()) { result << "," << arg6; } } } } } } result << ");"; } return result.str(); }
bool DbUtil::runQuery(const char* sql, const Properties& args, SqlResultSet& rows){ clear_error(); rows.clear(); if (!isConnected()) return false; assert(m_mysql); g_debug << "runQuery: " << endl << " sql: '" << sql << "'" << endl; MYSQL_STMT *stmt= mysql_stmt_init(m_mysql); if (mysql_stmt_prepare(stmt, sql, (unsigned long)strlen(sql))) { report_error("Failed to prepare: ", m_mysql); return false; } uint params= mysql_stmt_param_count(stmt); MYSQL_BIND *bind_param = new MYSQL_BIND[params]; NdbAutoObjArrayPtr<MYSQL_BIND> _guard(bind_param); memset(bind_param, 0, params * sizeof(MYSQL_BIND)); for(uint i= 0; i < mysql_stmt_param_count(stmt); i++) { BaseString name; name.assfmt("%d", i); // Parameters are named 0, 1, 2... if (!args.contains(name.c_str())) { g_err << "param " << i << " missing" << endl; assert(false); } PropertiesType t; Uint32 val_i; const char* val_s; args.getTypeOf(name.c_str(), &t); switch(t) { case PropertiesType_Uint32: args.get(name.c_str(), &val_i); bind_param[i].buffer_type= MYSQL_TYPE_LONG; bind_param[i].buffer= (char*)&val_i; g_debug << " param" << name.c_str() << ": " << val_i << endl; break; case PropertiesType_char: args.get(name.c_str(), &val_s); bind_param[i].buffer_type= MYSQL_TYPE_STRING; bind_param[i].buffer= (char*)val_s; bind_param[i].buffer_length= (unsigned long)strlen(val_s); g_debug << " param" << name.c_str() << ": " << val_s << endl; break; default: assert(false); break; } } if (mysql_stmt_bind_param(stmt, bind_param)) { report_error("Failed to bind param: ", m_mysql); mysql_stmt_close(stmt); return false; } if (mysql_stmt_execute(stmt)) { report_error("Failed to execute: ", m_mysql); mysql_stmt_close(stmt); return false; } /* Update max_length, making it possible to know how big buffers to allocate */ my_bool one= 1; mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*) &one); if (mysql_stmt_store_result(stmt)) { report_error("Failed to store result: ", m_mysql); mysql_stmt_close(stmt); return false; } uint row= 0; MYSQL_RES* res= mysql_stmt_result_metadata(stmt); if (res != NULL) { MYSQL_FIELD *fields= mysql_fetch_fields(res); uint num_fields= mysql_num_fields(res); MYSQL_BIND *bind_result = new MYSQL_BIND[num_fields]; NdbAutoObjArrayPtr<MYSQL_BIND> _guard1(bind_result); memset(bind_result, 0, num_fields * sizeof(MYSQL_BIND)); for (uint i= 0; i < num_fields; i++) { unsigned long buf_len= sizeof(int); switch(fields[i].type){ case MYSQL_TYPE_STRING: buf_len = fields[i].length + 1; break; case MYSQL_TYPE_VARCHAR: case MYSQL_TYPE_VAR_STRING: buf_len= fields[i].max_length + 1; break; case MYSQL_TYPE_LONGLONG: buf_len= sizeof(long long); break; case MYSQL_TYPE_LONG: buf_len = sizeof(long); break; default: break; } bind_result[i].buffer_type= fields[i].type; bind_result[i].buffer= malloc(buf_len); bind_result[i].buffer_length= buf_len; bind_result[i].is_null = (my_bool*)malloc(sizeof(my_bool)); * bind_result[i].is_null = 0; } if (mysql_stmt_bind_result(stmt, bind_result)){ report_error("Failed to bind result: ", m_mysql); mysql_stmt_close(stmt); return false; } while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) { Properties curr(true); for (uint i= 0; i < num_fields; i++){ if (* bind_result[i].is_null) continue; switch(fields[i].type){ case MYSQL_TYPE_STRING: ((char*)bind_result[i].buffer)[fields[i].max_length] = 0; case MYSQL_TYPE_VARCHAR: case MYSQL_TYPE_VAR_STRING: curr.put(fields[i].name, (char*)bind_result[i].buffer); break; case MYSQL_TYPE_LONGLONG: curr.put64(fields[i].name, *(unsigned long long*)bind_result[i].buffer); break; default: curr.put(fields[i].name, *(int*)bind_result[i].buffer); break; } } rows.put("row", row++, &curr); } mysql_free_result(res); for (uint i= 0; i < num_fields; i++) { free(bind_result[i].buffer); free(bind_result[i].is_null); } } // Save stats in result set rows.put("rows", row); rows.put64("affected_rows", mysql_affected_rows(m_mysql)); rows.put("mysql_errno", mysql_errno(m_mysql)); rows.put("mysql_error", mysql_error(m_mysql)); rows.put("mysql_sqlstate", mysql_sqlstate(m_mysql)); rows.put64("insert_id", mysql_insert_id(m_mysql)); mysql_stmt_close(stmt); return true; }
RoomId CRoom::getExitLeadsTo(ExitDirection dir) const { if (isConnected(dir) == false) return NULL; return room.exits().Get(dir).leads_to_id(); }
void SessionImpl::open(const std::string& connect) { if (connect != connectionString()) { if (isConnected()) throw InvalidAccessException("Session already connected"); if (!connect.empty()) setConnectionString(connect); } poco_assert_dbg (!connectionString().empty()); SQLULEN tout = static_cast<SQLULEN>(getLoginTimeout()); if (Utility::isError(SQLSetConnectAttr(_db, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER) tout, 0))) { if (Utility::isError(SQLGetConnectAttr(_db, SQL_ATTR_LOGIN_TIMEOUT, &tout, 0, 0)) || getLoginTimeout() != tout) { ConnectionError e(_db); throw ConnectionFailedException(e.toString()); } } SQLCHAR connectOutput[512] = {0}; SQLSMALLINT result; if (Utility::isError(Poco::Data::ODBC::SQLDriverConnect(_db , NULL ,(SQLCHAR*) connectionString().c_str() ,(SQLSMALLINT) SQL_NTS , connectOutput , sizeof(connectOutput) , &result , SQL_DRIVER_NOPROMPT))) { ConnectionError err(_db); std::string errStr = err.toString(); close(); throw ConnectionFailedException(errStr); } _dataTypes.fillTypeInfo(_db); addProperty("dataTypeInfo", &SessionImpl::setDataTypeInfo, &SessionImpl::dataTypeInfo); addFeature("autoCommit", &SessionImpl::autoCommit, &SessionImpl::isAutoCommit); addFeature("autoBind", &SessionImpl::autoBind, &SessionImpl::isAutoBind); addFeature("autoExtract", &SessionImpl::autoExtract, &SessionImpl::isAutoExtract); addProperty("maxFieldSize", &SessionImpl::setMaxFieldSize, &SessionImpl::getMaxFieldSize); addProperty("queryTimeout", &SessionImpl::setQueryTimeout, &SessionImpl::getQueryTimeout); Poco::Data::ODBC::SQLSetConnectAttr(_db, SQL_ATTR_QUIET_MODE, 0, 0); if (!canTransact()) autoCommit("", true); }
void FishCampCCD::TimerHit() { int timerHitID = -1, state = -1, rc = -1; long timeleft; double ccdTemp; if (isConnected() == false) return; // No need to reset timer if we are not connected anymore if (InExposure) { timeleft = CalcTimeLeft(); if (timeleft < 1.0) { if (timeleft > 0.25) { // a quarter of a second or more // just set a tighter timer timerHitID = SetTimer(250); } else { if (timeleft > 0.07) { // use an even tighter timer timerHitID = SetTimer(50); } else { // it's real close now, so spin on it while (!sim && timeleft > 0) { state = fcUsb_cmd_getState(cameraNum); if (state == 0) timeleft = 0; int slv; slv = 100000 * timeleft; usleep(slv); } /* We're done exposing */ DEBUG(INDI::Logger::DBG_DEBUG, "Exposure done, downloading image..."); PrimaryCCD.setExposureLeft(0); InExposure = false; /* grab and save image */ grabImage(); } } } else { DEBUGF(INDI::Logger::DBG_DEBUG, "Image not yet ready. With time left %ld\n", timeleft); } PrimaryCCD.setExposureLeft(timeleft); } switch (TemperatureNP.s) { case IPS_IDLE: case IPS_OK: rc = fcUsb_cmd_getTemperature(cameraNum); DEBUGF(INDI::Logger::DBG_DEBUG, "fcUsb_cmd_getTemperature returns %d", rc); ccdTemp = rc / 100.0; DEBUGF(INDI::Logger::DBG_DEBUG, "Temperature %g", ccdTemp); if (fabs(TemperatureN[0].value - ccdTemp) >= TEMP_THRESHOLD) { TemperatureN[0].value = ccdTemp; IDSetNumber(&TemperatureNP, NULL); } break; case IPS_BUSY: if (sim) { TemperatureN[0].value = TemperatureRequest; } else { rc = fcUsb_cmd_getTemperature(cameraNum); DEBUGF(INDI::Logger::DBG_DEBUG, "fcUsb_cmd_getTemperature returns %d", rc); TemperatureN[0].value = rc / 100.0; } // If we're within threshold, let's make it BUSY ---> OK if (fabs(TemperatureRequest - TemperatureN[0].value) <= TEMP_THRESHOLD) TemperatureNP.s = IPS_OK; IDSetNumber(&TemperatureNP, NULL); break; case IPS_ALERT: break; } switch (CoolerNP.s) { case IPS_OK: CoolerN[0].value = fcUsb_cmd_getTECPowerLevel(cameraNum); IDSetNumber(&CoolerNP, NULL); DEBUGF(INDI::Logger::DBG_DEBUG, "Cooler power level %g %", CoolerN[0].value); break; default: break; } if (timerHitID == -1) SetTimer(POLLMS); return; }
QTcpServerConnection::~QTcpServerConnection() { if (isConnected()) disconnect(); delete d_ptr; }
// attempt to determine if the device at the given address is connected to the bus bool DallasTemperature::isConnected(uint8_t* deviceAddress) { ScratchPad scratchPad; return isConnected(deviceAddress, scratchPad); }
void VisibilityLayout::constructDualGraph(UpwardPlanRep &UPR) { CombinatorialEmbedding &gamma = UPR.getEmbedding(); faceToNode.init(gamma, nullptr); leftFace_node.init(UPR, nullptr); rightFace_node.init(UPR, nullptr); leftFace_edge.init(UPR, nullptr); rightFace_edge.init(UPR, nullptr); //construct a node for each face f for(face f : gamma.faces) { faceToNode[f] = D.newNode(); if (f == gamma.externalFace()) s_D = faceToNode[f] ; //compute face switches node s = nullptr, t = nullptr; for(adjEntry adj : f->entries) { adjEntry adjNext = adj->faceCycleSucc(); if (adjNext->theEdge()->source() == adj->theEdge()->source()) s = adjNext->theEdge()->source(); if (adjNext->theEdge()->target() == adj->theEdge()->target()) t = adjNext->theEdge()->target(); } OGDF_ASSERT(s); OGDF_ASSERT(t); //compute left and right face bool passSource = false; adjEntry adj; if (f == gamma.externalFace()) { adj = UPR.getSuperSink()->firstAdj(); if (gamma.rightFace(adj) != gamma.externalFace()) adj = adj->cyclicSucc(); } else adj = UPR.getAdjEntry(gamma, t, f); adjEntry adjBegin = adj; do { node v = adj->theEdge()->source(); if (!passSource) { if (v != s) leftFace_node[v] = f; leftFace_edge[adj->theEdge()] = f; } else { if (v != s) rightFace_node[v] = f; rightFace_edge[adj->theEdge()] = f; } if (adj->theEdge()->source() == s) passSource = true; adj = adj->faceCycleSucc(); } while(adj != adjBegin); } t_D = D.newNode(); // the second (right) node associated with the external face //construct dual edges for(edge e : UPR.edges) { face f_r = rightFace_edge[e]; face f_l = leftFace_edge[e]; node u = faceToNode[f_l]; node v = faceToNode[f_r]; if (f_r == gamma.externalFace() || f_r == f_l) D.newEdge(u, t_D); else D.newEdge(u,v); } OGDF_ASSERT(isConnected(D)); }