Bonjour !

Je suis nouveau sur ce forum, et je suis d'ailleurs désolé de commencer mon premier POST par une questions

Tout d'abord, j'avoue n'avoir pas cherché une réponse a ma questions sur les topic déjà existant car je ne sais comment la formulé en quelques mots. Essayé de ne pas trop m'en vouloir

Donc, voilà, dans ma bibliothèque réseau, je doit utilisé un header (filesender.cpp et filesender.h écrit par son auteur).
A l'intérieur je peux renvoyer a l'aide de printf l'état du téléchargement (transféré, poids total, pourcentage)

En somme ça se présente comme ça :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
void FileSender::processNodeEvents()
{
  while (m_node->checkEventWaiting())
  {
        if (eve_type == eZCom_EventFile_Data)
    {
 
 
       ZCom_FileTransID fid = (ZCom_FileTransID) eve_data->getInt(ZCOM_FTRANS_ID_BITS);
       const ZCom_FileTransInfo& ftransinfo = m_node->getFileInfo(eve_connid, fid);
       printf("File transfer: received: %0.2f kb, total: %0.2f kb, percent: %0.2f%%, kb/s: %0.2f\r", ftransinfo.transferred/1024.0f, ftransinfo.size/1024.0f, ((float)ftransinfo.transferred/(float)ftransinfo.size)*100.0f, ftransinfo.bps/1024.0f);
       int test = ftransinfo.transferred/1024;
 
 
    }
 
 }
Je le "déclare" de comme ça dans le main :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
class Client : public ZCom_Control
{
public:
  // constructor - gets called when the client is created with new Client(...)
  Client()
  {
    // this will allocate the sockets and create local bindings
    if ( !ZCom_initSockets( true, 0, 0, 0 ) )
    {
      printf("Failed to initialize sockets!\n");
      // exit program immediately
      exit(255);
    }
 
    // string shown in log output
    ZCom_setDebugName("ZCOM_CLI");
 
  }
 
protected:
 
  // called when client finished entering zoidlevel
  void ZCom_cbZoidResult(ZCom_ConnID _id, eZCom_ZoidResult _result, zU8 _new_level, ZCom_BitStream &_reason)
  {
    if (_result == eZCom_ZoidEnabled)
      printf("Client entered Zoidlevel: %d\n", _new_level);
    else
      printf("Client failed entering Zoidlevel: %d\n", _new_level);
  }
 
  // called when the connecting ends
  void ZCom_cbConnectResult( ZCom_ConnID _id, eZCom_ConnectResult _result, ZCom_BitStream &_reply )
  {
    // connection successful?
    if (_result == eZCom_ConnAccepted)
    {
      ZCom_requestDownstreamLimit(_id, 100, 500);
      printf("Connected! Let's request Zoidlevel 1...\n");
 
      ZCom_requestZoidMode(_id, 1);
    }
    else
    {
      printf("Connection failed!\n");
      ZoidCom::Sleep(2000);
      // when connection failed, exit program
      exit(255);
    }
  }
 
  // called when a connection closed
  void ZCom_cbConnectionClosed( ZCom_ConnID _id, eZCom_CloseReason _reason, ZCom_BitStream &_reasondata )
  {
    printf("Connection closed!\n");
    ZoidCom::Sleep(2000);
    exit(0);
  }
 
  // called when data has been received
  void ZCom_cbDataReceived( ZCom_ConnID _id, ZCom_BitStream &_data )
  {
    // we assume that clients will only send strings
    // so no special handling, just output of incoming data
    printf("Received from server: %s\n", _data.getStringStatic());
  }
 
 
  // unused callbacks are empty
  void ZCom_cbNodeRequest_Dynamic( ZCom_ConnID _id, ZCom_ClassID _requested_class, ZCom_BitStream *_announcedata, eZCom_NodeRole _role, ZCom_NodeID _net_id ) {}
  void ZCom_cbConnectionSpawned( ZCom_ConnID _id ) {}
  bool ZCom_cbConnectionRequest( ZCom_ConnID  _id, ZCom_BitStream &_request, ZCom_BitStream &_reply ){return false;}
  bool ZCom_cbZoidRequest( ZCom_ConnID _id, zU8 _requested_level, ZCom_BitStream &_reason) {return false;}
  bool ZCom_cbDiscoverRequest(const ZCom_Address &_addr, ZCom_BitStream &_request, ZCom_BitStream &_reply) {return false;}
  void ZCom_cbNodeRequest_Tag( ZCom_ConnID _id, ZCom_ClassID _requested_class, ZCom_BitStream *_announcedata, eZCom_NodeRole _role, zU32 _tag ) {}
  void ZCom_cbDiscovered( const ZCom_Address & _addr, ZCom_BitStream &_reply )  {}
};
Et je "l'appel" de tel sorte dans le main :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
 while (1)
  {
    // processes incoming packets
    // all callbacks are generated from within the processInput calls
    cli->ZCom_processInput( eZCom_NoBlock );
 
    // outstanding data will be packed up and sent from here
    cli->ZCom_processOutput();
 
    // clean up garbage objects
    fsender->processNodeEvents();
 
    // pause the program for a few milliseconds
    ZoidCom::Sleep(10);
  }
Donc quand le programme est lancé, le printf renvoi au fur et a mesure l'évolution du téléchargement.
Cependant, mon programme est en SDL, donc le printf ne fonctionne pas.

Comment puis je récupérer la valeur de cette évolution dans mon main pour faire une barre de chargement ?


J'éspert que vous m'avez comprit... (sinon vous me demande : je peux aussi passé tout le code)

Merci d'avance de votre aide.

a+
w