110 lines
2.3 KiB
Plaintext
Executable File
110 lines
2.3 KiB
Plaintext
Executable File
#include <stdio.h>
|
|
#include "master.h"
|
|
|
|
int MASTERID = 0;
|
|
int activeNodes[10]; //nodes active in the network. Assumes that all nodes have a unique id.
|
|
char *currentPrograms[100]; //current programs : array of char pointers, each is a program string.
|
|
|
|
void main()
|
|
{
|
|
initCurrentProgramsArray();
|
|
|
|
int newProgramIndex = manageUserInput();
|
|
printf("New program : %s \n", currentPrograms[newProgramIndex]);
|
|
/*
|
|
for(;;)
|
|
{
|
|
manageUserInput();
|
|
|
|
printf("Entrez le nom d'un programme : \n >> ") ;
|
|
scanf("%s", program );
|
|
|
|
|
|
printf(" %d ", sizeof(program));
|
|
addToCurrentPrograms(program);
|
|
|
|
//calls roundRobin to decide where it should be executed
|
|
//sends it over the network
|
|
//gets program return output and print
|
|
|
|
|
|
}*/
|
|
}
|
|
|
|
void initCurrentProgramsArray()
|
|
{
|
|
int i=0;
|
|
while(i<sizeof(currentPrograms)){
|
|
currentPrograms[i] = NULL;
|
|
i++;
|
|
}
|
|
}
|
|
|
|
// adds the program string to current program array, and returns the index where it was added.
|
|
int addToCurrentPrograms(char* newProgram){
|
|
int i=0;
|
|
while(i<sizeof(currentPrograms))
|
|
{
|
|
if(currentPrograms[i] == "-1"){
|
|
currentPrograms[i] = newProgram;
|
|
printf("Empty program at %d", i);
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
return i ;
|
|
}
|
|
|
|
int commandSlaveNode(int programIndex)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
int roundRobin()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
void printProgramOutput(char programName[])
|
|
{
|
|
|
|
}
|
|
|
|
/*********************
|
|
* UTIL ARRAY FUNCTIONS
|
|
*********************/
|
|
|
|
int returnsSizeOfOccupiedArray(char array[]){
|
|
int i=0;
|
|
while(i<sizeof(array))
|
|
{
|
|
if(array[i]==NULL)
|
|
break;
|
|
i++;
|
|
}
|
|
return i;
|
|
}
|
|
|
|
// copies content of bigger array to smaller one, fitting everything it cans in the smaller array.
|
|
void copyToSmallerArray(char bigArray[], char smallArray[])
|
|
{
|
|
int i=0;
|
|
while(i<sizeof(smallArray))
|
|
{
|
|
smallArray[i]=bigArray[i];
|
|
i++;
|
|
}
|
|
}
|
|
|
|
int manageUserInput()
|
|
{
|
|
char program[50];
|
|
printf("Entrez un programme à exécuter : \n");
|
|
scanf("%s", program );
|
|
char smallarray[returnsSizeOfOccupiedArray(program)];
|
|
copyToSmallerArray(program, smallarray);
|
|
|
|
int index = addToCurrentPrograms(smallarray);
|
|
return index;
|
|
}
|