int spoutSenderNames::GetSenderCount() { std::set<string> SenderSet; std::set<string>::iterator iter; string namestring; char name[SpoutMaxSenderNameLen]; SharedTextureInfo info; // Create the shared memory for the sender name set if it does not exist if(!CreateSenderSet()) { return 0; } // Doing multiple operations on the sender list, keep it locked if (!m_senderNames.Lock()) { return 0; } // get the name list in shared memory into a local list GetSenderNames(&SenderSet); // Now we have a local set of names // 27.12.13 - noted that if a Processing sketch is stopped by closing the window // all is OK and either the "stop" or "dispose" overrides work, but if STOP is used, // or the sketch is closed, neither the exit or dispose functions are called and // the sketch does not release the sender. // So here we run through again and check whether the sender exists and if it does not // release the sender from the local sender list if(SenderSet.size() > 0) { for(iter = SenderSet.begin(); iter != SenderSet.end(); iter++) { namestring = *iter; // the Sender name string strcpy_s(name, namestring.c_str()); // we have the name already, so look for it's info if(!getSharedInfo(name, &info)) { // Sender does not exist any more ReleaseSenderName(name); // release from the shared memory list } } } // Get the new set back if(GetSenderNames(&SenderSet)) { m_senderNames.Unlock(); return(SenderSet.size()); } m_senderNames.Unlock(); return 0; }
// Get sender info given a sender index and knowing the sender count // index - in // sendername - out // sendernameMaxSize - in // width, height, dxShareHandle - out bool spoutSenderNames::GetSenderNameInfo(int index, char* sendername, int sendernameMaxSize, unsigned int &width, unsigned int &height, HANDLE &dxShareHandle) { char name[SpoutMaxSenderNameLen]; std::set<std::string> SenderNameSet; std::set<std::string>::iterator iter; std::string namestring; int i; DWORD format; if(GetSenderNames(&SenderNameSet)) { if(SenderNameSet.size() < (unsigned int)index) return false; i = 0; for(iter = SenderNameSet.begin(); iter != SenderNameSet.end(); iter++) { namestring = *iter; // the name string strcpy_s(name, namestring.c_str()); // the 256 byte name char array if(i == index) { strcpy_s(sendername, sendernameMaxSize, name); // the passed name char array break; } i++; } // Does the retrieved sender exist or has it crashed? // Find out by getting the sender info and returning it if(GetSenderInfo(sendername, width, height, dxShareHandle, format)) return true; } return false; } // end GetSenderNameInfo
//--------------------------------------------------------- bool spoutSenderNames::SenderDebug(const char *Sendername, int size) { // HANDLE hMap1 = NULL; // HANDLE hMap2 = NULL; // HANDLE hMap3 = NULL; std::set<string> SenderNames; std::set<string>::iterator iter; string namestring; UNREFERENCED_PARAMETER(Sendername); UNREFERENCED_PARAMETER(size); printf("**** SENDER DEBUG ****\n"); m_senderNames.Debug(); // Check the sender names /* // printf(" GetSenderSet\n"); if(GetSenderSet(SenderNames)) { // printf(" SenderNames size = [%d]\n", SenderNames.size()); if (SenderNames.size() > 0) { for(iter = SenderNames.begin(); iter != SenderNames.end(); iter++) { namestring = *iter; // printf(" Sender : [%s]\n", namestring.c_str()); } } } else { // printf(" GetSenderSet failed\n"); } */ printf(" GetSenderNames\n"); if(GetSenderNames(&SenderNames)) { printf(" SenderNames size = [%d]\n", SenderNames.size()); if (SenderNames.size() > 0) { for(iter = SenderNames.begin(); iter != SenderNames.end(); iter++) { namestring = *iter; printf(" Sender : [%s]\n", namestring.c_str()); } } else { printf(" SenderNames size = 0\n"); } } else { printf(" GetSenderSet failed\n"); } /* // printf("2) Closing - hSenderNamesMap = [%x], pSenderNamesMap = [%x]\n", m_hSenderNamesMap, m_pSenderNamesMap); // Close and try to reopen CloseMap(m_pSenderNamesMap, m_hSenderNamesMap); hMap2 = OpenFileMappingA (FILE_MAP_ALL_ACCESS, FALSE, "SpoutSenderNames"); if(hMap2) { // printf(" Sendernames map [%x] did not close\n", hMap2); CloseHandle(hMap2); } else { // printf(" Closed sendernames map OK\n"); } CloseMap(m_pActiveSenderMap, m_hActiveSenderMap); */ m_activeSender.Debug(); return true; }