void KoodevStopwatch::dump() { long prevTime = 0; for (unsigned int i = 0; i < m_labTimeRecords.size(); i++) { const long currentTime = getTime(m_labTimeRecords[i].labTimeval); const long labTime = currentTime - prevTime; prevTime = currentTime; if (labTime > 0 || !m_ignoreZeroDump) dumpMessage(labTime, m_labTimeRecords[i].tag.data()); } if (!m_started) { const long labTime = getTime(); if (labTime > 0 || !m_ignoreZeroDump) dumpMessage(labTime); } }
void QDBusViewer::setProperty(const BusSignature &sig) { QDBusInterface iface(sig.mService, sig.mPath, sig.mInterface, c); QMetaProperty prop = iface.metaObject()->property(iface.metaObject()->indexOfProperty(sig.mName.toLatin1())); bool ok; QString input = QInputDialog::getText(this, tr("Arguments"), tr("Please enter the value of the property %1 (type %2)").arg( sig.mName, QString::fromLatin1(prop.typeName())), QLineEdit::Normal, QString(), &ok); if (!ok) return; QVariant value = input; if (!value.convert(prop.type())) { QMessageBox::warning(this, tr("Unable to marshall"), tr("Value conversion failed, unable to set property")); return; } QDBusMessage message = QDBusMessage::createMethodCall(sig.mService, sig.mPath, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("Set")); QList<QVariant> arguments; arguments << sig.mInterface << sig.mName << qVariantFromValue(QDBusVariant(value)); message.setArguments(arguments); c.callWithCallback(message, this, SLOT(dumpMessage(QDBusMessage))); }
void QDBusViewer::connectionRequested(const BusSignature &sig) { if (!c.connect(sig.mService, QString(), sig.mInterface, sig.mName, this, SLOT(dumpMessage(QDBusMessage)))) { logError(tr("Unable to connect to service %1, path %2, interface %3, signal %4").arg( sig.mService).arg(sig.mPath).arg(sig.mInterface).arg(sig.mName)); } }
void QDBusViewer::getProperty(const BusSignature &sig) { QDBusMessage message = QDBusMessage::createMethodCall(sig.mService, sig.mPath, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("Get")); QList<QVariant> arguments; arguments << sig.mInterface << sig.mName; message.setArguments(arguments); c.callWithCallback(message, this, SLOT(dumpMessage(QDBusMessage))); }
void QDBusViewer::callMethod(const BusSignature &sig) { QDBusInterface iface(sig.mService, sig.mPath, sig.mInterface, c); const QMetaObject *mo = iface.metaObject(); // find the method QMetaMethod method; for (int i = 0; i < mo->methodCount(); ++i) { const QString signature = QString::fromLatin1(mo->method(i).signature()); if (signature.startsWith(sig.mName) && signature.at(sig.mName.length()) == QLatin1Char('(')) if (getDbusSignature(mo->method(i)) == sig.mTypeSig) method = mo->method(i); } if (!method.signature()) { QMessageBox::warning(this, tr("Unable to find method"), tr("Unable to find method %1 on path %2 in interface %3").arg( sig.mName).arg(sig.mPath).arg(sig.mInterface)); return; } PropertyDialog dialog; QList<QVariant> args; const QList<QByteArray> paramTypes = method.parameterTypes(); const QList<QByteArray> paramNames = method.parameterNames(); QList<int> types; // remember the low-level D-Bus type for (int i = 0; i < paramTypes.count(); ++i) { const QByteArray paramType = paramTypes.at(i); if (paramType.endsWith('&')) continue; // ignore OUT parameters QVariant::Type type = QVariant::nameToType(paramType); dialog.addProperty(QString::fromLatin1(paramNames.value(i)), type); types.append(QMetaType::type(paramType)); } if (!types.isEmpty()) { dialog.setInfo(tr("Please enter parameters for the method \"%1\"").arg(sig.mName)); if (dialog.exec() != QDialog::Accepted) return; args = dialog.values(); } // Special case - convert a value to a QDBusVariant if the // interface wants a variant for (int i = 0; i < args.count(); ++i) { if (types.at(i) == qMetaTypeId<QDBusVariant>()) args[i] = qVariantFromValue(QDBusVariant(args.at(i))); } QDBusMessage message = QDBusMessage::createMethodCall(sig.mService, sig.mPath, sig.mInterface, sig.mName); message.setArguments(args); c.callWithCallback(message, this, SLOT(dumpMessage(QDBusMessage))); }
int handleMessage(struct __message msg) { struct timeval timeFinished; gettimeofday(&timeFinished, NULL); msg.client_finished.tv_sec = timeFinished.tv_sec; msg.client_finished.tv_usec = timeFinished.tv_usec; dumpMessage(msg); return 0; }
static void dumpBodypart( Message * m, Bodypart * bp, int n ) { dumpMultipart( bp, n ); if ( bp->message() ) { dumpMessage( bp->message(), n+4 ); } else { List< Bodypart >::Iterator it( bp->children() ); while ( it ) { dumpBodypart( m, it, n+2 ); ++it; } } }
/****************************************************************************** * Function 'runForever' * This function will do most of the programs work. It will take in all the packets * (which realistically, should make this a continuously running function) and call * the function for them to be read. It will take these read packets and add them to * messages and then add these messages to the MessagesMap. It will test if a message * has been completed upon the addition of a packet and call the messageDump function * to remove and output a message if it is done. In the scale of this program, this function * runs until all the messages are complete and there are no more packets to take in. * * Parameters: * scanner - the 'Scanner' from which to read * outStream - the stream to which to write * * Returns: None * * Output: Adds each completed message to the OutStream. **/ void PacketAssembler::runForever(Scanner& scanner, ofstream& outStream) { #ifdef EBUG Utils::logStream << "enter runForever\n"; #endif Packet tempPacket; int tempMessageID; //run as long as there are more packets to take in. while(scanner.hasNext()) { //create a temporary packet and call the read from the Packet class to assign it values tempPacket = Packet(scanner); tempMessageID = tempPacket.getMessageID(); //using this packets MessageID, check if we already have this message if (messagesMapContains(tempMessageID) == false) { //if not create a new Message and push it into the messagesMap Message tempMessage; tempMessage.insert(tempPacket); messagesMap.insert(std::pair<int, Message>(tempMessageID, tempMessage)); } //otherwise, this message is in the Messages map and we should just add the new //packet to the message already in the messages map. else { if(messagesMapContains(tempMessageID)) { messagesMap[tempMessageID].insert(tempPacket); } } //after adding each packet, we should check if that packet completed a message if (messagesMap[tempMessageID].isComplete() == true) { //if it did, dump it and outStream the data. outStream << "The Completed message is: "; outStream << "\n"; outStream << dumpMessage(tempMessageID); } } #ifdef EBUG Utils::logStream << "leave runForever\n"; #endif }
int handleMessage(struct __message *arg) { struct timeval timeStart, timeEnd; struct __message msg; //TODO: rx delay usleep(DELAY_SERVER_RX*1000); memcpy(&msg, arg, sizeof(struct __message)); gettimeofday(&timeStart, NULL); #if ENABLE_MUTEX pthread_mutex_lock(&m_lock); #endif //TODO: process delay usleep(DELAY_SERVER_PROCESS*1000); #if ENABLE_MUTEX pthread_mutex_unlock(&m_lock); #endif //#if ENABLE_MUTEX gettimeofday(&timeEnd, NULL); setTimeValue(&(msg.server_started), timeStart.tv_sec, timeStart.tv_usec); setTimeValue(&(msg.server_finished), timeEnd.tv_sec, timeEnd.tv_usec); #if 0 msg.resource = timeEnd.tv_sec%1000000; msg.uiMaxAge = (1000000-timeEnd.tv_usec)/1000; #else msg.resource = g_iCount++; msg.uiMaxAge = (DELAY_SERVER_PROCESS); #endif //TODO: tx delay usleep(DELAY_SERVER_TX*1000); //printf("[%d-%d]Resource=%d, uiMaxAge=%d, msg.iFd=%d ", msg.owner, msg.cnt, msg.resource, msg.uiMaxAge, msg.iFd); int temp = send(msg.iFd, &msg, sizeof(struct __message), 0); #if 1 dumpMessage(msg); #endif return 0; }
void *pthreadWatchResource(void *arg) { struct timeval timeSched; struct timeval tStart; while(!g_iExit) { if(g_Resource1.iClientNumber) { //TODO: get current time //gettimeofday(&tStart, NULL); //TODO: search all clients registered struct __client *client = g_Resource1.next; while(client) { gettimeofday(&tStart, NULL); //TODO: find scheduled client if(isBiggerThan(tStart, client->tSched)) { struct __message msg; struct timeval tEnd; //TODO: if cached resource is valid, then use it if(g_uiCacheMode && isCachedDataValid(tStart) ) { //TODO: update cache timing information updateCache(tStart); //TODO: set server process time with zero setTimeValue(&(msg.server_recved), 0, 0); setTimeValue(&(msg.server_started), 0, 0); setTimeValue(&(msg.server_finished), 0, 0); //TODO: set message with time information msg.resource = g_Resource1.iCachedResource; msg.uiMaxAge = g_Resource1.uiMaxAge - g_Resource1.uiCachedAge; //printf("%s:uiMaxAge=%d(%d-%d)\n", __func__, msg.uiMaxAge, g_Resource1.uiMaxAge, g_Resource1.uiCachedAge); //TODO: get current time gettimeofday(&tEnd, NULL); } else { //TODO: init cache initCache(); //TODO: get a fresh resource from a server getResourceFromServer(&msg); //TODO: get current time gettimeofday(&tEnd, NULL); //TODO: set cached with information setCache(msg, tEnd); } //TODO: set client process time setTimeValue(&(msg.client_recved), 0, 0); setTimeValue(&(msg.client_started), 0, 0); //TODO: set proxy process time setTimeValue(&(msg.proxy_recved), tStart.tv_sec, tStart.tv_usec); setTimeValue(&(msg.proxy_started), tStart.tv_sec, tStart.tv_usec); setTimeValue(&(msg.proxy_finished), tEnd.tv_sec, tEnd.tv_usec); //TODO: dump message dumpMessage(msg); //TODO: send information as response from proxy to client int temp = send(client->iFd, &msg, sizeof(struct __message), 0); //TODO: set a new scheduled time of client struct timeval tB; tB.tv_sec = client->uiReqInterval/1000; tB.tv_usec = (client->uiReqInterval%1000)*1000; addTimeValue(&(client->tSched), client->tSched, tB); //printf("tStart=%ld.%06ld, tSched=%ld.%06ld\n", // tStart.tv_sec, tStart.tv_usec, // client->tSched.tv_sec, client->tSched.tv_usec); } client = client->next; //printf("%s:client=0x%x\n", __func__, (unsigned int)client); } //TODO: inser client node as time sequence //updateClient(); //TODO: if(g_uiCacheAlgorithm == 1) { if(isBiggerThan(tStart, g_Resource1.tBaseTime)) { //TODO: update check point updateBaseTime(); } } else if(g_uiCacheAlgorithm == 2) { struct timeval tCPaddMA; struct timeval tMaxAge; setTimeValue(&tMaxAge, g_Resource1.uiMaxAge/1000, (g_Resource1.uiMaxAge%1000)*1000); addTimeValue(&tCPaddMA, g_Resource1.tBaseTime, tMaxAge); if(isBiggerThan(tStart, tCPaddMA)) { setSchedule(tStart); } } usleep(5*1000); } //if(g_Resource1.iClientNumber) usleep(50*1000); } return NULL; }
int handleMessage(struct __message *arg) { struct timeval tStart; struct __message msg = {0x0, }; struct __message resp = {0x0, }; memcpy(&msg, arg, sizeof(struct __message)); //TODO: handle packet //gettimeofday(&tStart, NULL); //TODO: wait until other request responded pthread_mutex_lock(&m_lock); gettimeofday(&tStart, NULL); //TODO: use cached resource if(msg.cmd == RESOURCE_CMD_REGISTER) { if(g_uiCacheAlgorithm == 0) { addObserver0(msg.owner, msg.iFd, msg.resource, msg.req_dur); } else if(g_uiCacheAlgorithm == 1) { addObserver1(msg.owner, msg.iFd, msg.resource, msg.req_dur, tStart); } else if(g_uiCacheAlgorithm == 2) { addObserver1(msg.owner, msg.iFd, msg.resource, msg.req_dur, tStart); } dumpObserver(); } else if (msg.cmd == RESOURCE_CMD_GET) { struct timeval tEnd; //TODO: get cached resource if(g_uiCacheMode && isCachedDataValid(tStart)) { //TODO: update cache timing information updateCache(tStart); //TODO: set server process time with zero setTimeValue(&(msg.server_recved), 0, 0); setTimeValue(&(msg.server_started), 0, 0); setTimeValue(&(msg.server_finished), 0, 0); //TODO: set message with time information gettimeofday(&tEnd, NULL); //TODO: set message with time information msg.resource = g_Resource1.iCachedResource; msg.uiMaxAge = g_Resource1.uiMaxAge - g_Resource1.uiCachedAge; printf("CACHED! Owner=%d, R=%d, MaxAge=%d, CachedAge=%d(%ld.%06ld)\n", msg.owner, g_Resource1.iCachedResource, g_Resource1.uiMaxAge, g_Resource1.uiCachedAge, tEnd.tv_sec%1000, \ tEnd.tv_usec ); } else { //TODO: init cache initCache(); //TODO: get a fresh resource from a server getResourceFromServer(&msg); //TODO: get current time gettimeofday(&tEnd, NULL); //TODO: set cached with information setCache(msg, tEnd); printf("NOT cached! Owner=%d, R=%d, MaxAge=%d, CachedAge=%d(%ld.%06ld)\n", msg.owner, g_Resource1.iCachedResource, g_Resource1.uiMaxAge, g_Resource1.uiCachedAge, tEnd.tv_sec%1000, \ tEnd.tv_usec ); } //TODO: set client process time //setTimeValue(&(msg.client_recved), 0, 0); //setTimeValue(&(msg.client_started), 0, 0); //TODO: set proxy process time //setTimeValue(&(msg.proxy_recved), tStart.tv_sec, tStart.tv_usec); setTimeValue(&(msg.proxy_started), tStart.tv_sec, tStart.tv_usec); setTimeValue(&(msg.proxy_finished), tEnd.tv_sec, tEnd.tv_usec); //TODO: send information as response from proxy to client int temp = send(msg.iFd, &msg, sizeof(struct __message), 0); //TODO: set a new scheduled time of client /* struct timeval tB; tB.tv_sec = client->uiReqInterval/1000; tB.tv_usec = (client->uiReqInterval%1000)*1000; addTimeValue(&(client->tSched), client->tSched, tB); */ #if 1 dumpMessage(msg); #endif } pthread_mutex_unlock(&m_lock); //printf("---\n"); return 0; }
/* * On linux this is not how we create processes. We send a message * to a server to clone itself, and then we message it. That is layered * on top of the messaging system */ static int create_process(char **cmd_args, int argc, char** argv) { JUMPPlatformCString type = "mvm/server"; JUMPOutgoingMessage outMessage; JUMPMessage response; JUMPMessageMark mark; JUMPAddress targetAddress; JUMPMessageStatusCode code; int numWords = 0; int i; char * vmArgs, *s; if (cmd_args == NULL || *cmd_args == NULL) { /* Nothing to do */ return -1; } outMessage = jumpMessageNewOutgoingByType(type, &code); jumpMessageMarkSet(&mark, outMessage); /* * We don't yet know how many strings we will be adding in, so * put in a placeholder for now. We marked the spot with &mark. */ jumpMessageAddInt(outMessage, numWords); /* Start with the command. It should be JAPP or JNATIVE */ jumpMessageAddString(outMessage, *cmd_args); numWords ++; cmd_args ++; /* * The argv[0] is the VM arugment, which needs to be placed * right after 'JAPP'. */ vmArgs = argv[0]; if (strcmp(vmArgs, "")) { s = strchr(vmArgs, ' '); while (s != NULL) { *s = '\0'; jumpMessageAddString(outMessage, vmArgs); numWords ++; vmArgs = s + 1; s = strchr(vmArgs, ' '); } if (*vmArgs != '\0') { jumpMessageAddString(outMessage, vmArgs); numWords ++; } } /* Rest of the cmd argument list: e.g. ..JUMPIsolateProcessImpl */ while (*cmd_args != NULL) { jumpMessageAddString(outMessage, *cmd_args); numWords ++; cmd_args ++; } /* * If we do argc, argv[] for main(), this is how we would put those in */ for (i = 1; i < argc; i++) { jumpMessageAddString(outMessage, (char*)argv[i]); } numWords = numWords + argc - 1; /* Now that we know what we are sending, patch message with count */ jumpMessageMarkResetTo(&mark, outMessage); jumpMessageAddInt(outMessage, numWords); /* And now, for dumping purposes */ jumpMessageMarkResetTo(&mark, outMessage); dumpMessage(outMessage, "Outgoing message:"); /* Time to send outgoing message */ targetAddress.processId = serverPid; /* FIXME: Must have central location for timeout values */ #define TIMEOUT 10000 response = jumpMessageSendSync(targetAddress, outMessage, TIMEOUT, &code); if (response == NULL) { return -1; } dumpMessage(response, "Command response:"); return getChildPid(response); }